Skip to content

Commit b1e78a9

Browse files
committed
Try reducing timeout and adding additional conditions.
1 parent 3dc8b40 commit b1e78a9

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

java-components/domain-proxy/client/src/main/java/com/redhat/hacbs/domainproxy/client/DomainProxyClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public void start() {
4545
try (final ServerSocket serverSocket = new ServerSocket(clientHttpPort)) {
4646
while (running) {
4747
final Socket socket = serverSocket.accept();
48-
socket.setSoTimeout(1200000);
48+
socket.setSoTimeout(1000);
4949
final UnixDomainSocketAddress address = UnixDomainSocketAddress.of(domainSocket);
5050
final SocketChannel channel = SocketChannel.open(address);
5151
// Write from socket to channel

java-components/domain-proxy/common/src/main/java/com/redhat/hacbs/domainproxy/common/CommonIOUtil.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.io.IOException;
44
import java.net.Socket;
55
import java.net.SocketException;
6+
import java.net.SocketTimeoutException;
67
import java.nio.ByteBuffer;
78
import java.nio.channels.AsynchronousCloseException;
89
import java.nio.channels.SocketChannel;
@@ -23,14 +24,16 @@ public static Runnable createSocketToChannelWriter(final int byteBufferSize, fin
2324
int bytesWritten = 0;
2425
LOG.info("Writing from socket to channel");
2526
try {
26-
while (!socket.isClosed() && socket.isConnected() && (r = socket.getInputStream().read(buf)) > 0) {
27+
while (socket.isConnected() && channel.isConnected() && socket.getInputStream().available() > 0 && (r = socket.getInputStream().read(buf)) > 0) {
2728
LOG.infof("Read %d bytes from socket", r);
2829
channel.write(ByteBuffer.wrap(buf, 0, r));
2930
LOG.infof("Wrote %d bytes to channel", r);
3031
bytesWritten += r;
3132
}
3233
} catch (final SocketException ignore) {
3334
LOG.info("Socket closed");
35+
} catch (final SocketTimeoutException ignore) {
36+
LOG.info("Socket timed out");
3437
} catch (final IOException e) {
3538
LOG.errorf(e, "Error writing from socket to channel");
3639
} finally {
@@ -60,7 +63,7 @@ public static Runnable createChannelToSocketWriter(final int byteBufferSize, fin
6063
int bytesWritten = 0;
6164
LOG.info("Writing from channel to socket");
6265
try {
63-
while (channel.isOpen() && channel.isConnected() && (r = channel.read(buf)) > 0) {
66+
while (channel.isConnected() && socket.isConnected() && (r = channel.read(buf)) > 0) {
6467
LOG.infof("Read %d bytes from channel", r);
6568
buf.flip();
6669
socket.getOutputStream().write(buf.array(), buf.arrayOffset(), buf.remaining());

java-components/domain-proxy/server/src/main/java/com/redhat/hacbs/domainproxy/DomainProxyServer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public void start() {
5959
while (running) {
6060
final SocketChannel channel = serverChannel.accept();
6161
final Socket socket = new Socket(LOCALHOST, httpServerPort);
62-
socket.setSoTimeout(1200000);
62+
socket.setSoTimeout(1000);
6363
// Write from socket to channel
6464
Thread.startVirtualThread(createSocketToChannelWriter(byteBufferSize, socket, channel));
6565
// Write from channel to socket

0 commit comments

Comments
 (0)