Skip to content

Commit 57d9871

Browse files
committed
Remove timeout and synchronise writes.
1 parent b4d2dce commit 57d9871

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

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

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

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

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@ public static Runnable createSocketToChannelWriter(final int byteBufferSize, fin
2525
LOG.info("Writing from socket to channel");
2626
try {
2727
while ((r = socket.getInputStream().read(buf)) > 0) {
28-
LOG.infof("Read %d bytes from socket", r);
29-
channel.write(ByteBuffer.wrap(buf, 0, r));
30-
LOG.infof("Wrote %d bytes to channel", r);
31-
bytesWritten += r;
28+
synchronized (channel) {
29+
LOG.infof("Read %d bytes from socket", r);
30+
channel.write(ByteBuffer.wrap(buf, 0, r));
31+
LOG.infof("Wrote %d bytes to channel", r);
32+
bytesWritten += r;
33+
}
3234
}
3335
} catch (final ClosedChannelException ignore) {
3436
LOG.info("Channel closed");
@@ -66,12 +68,14 @@ public static Runnable createChannelToSocketWriter(final int byteBufferSize, fin
6668
LOG.info("Writing from channel to socket");
6769
try {
6870
while ((r = channel.read(buf)) > 0) {
69-
LOG.infof("Read %d bytes from channel", r);
70-
buf.flip();
71-
socket.getOutputStream().write(buf.array(), buf.arrayOffset(), buf.remaining());
72-
LOG.infof("Wrote %d bytes to socket", r);
73-
buf.clear();
74-
bytesWritten += r;
71+
synchronized (socket) {
72+
LOG.infof("Read %d bytes from channel", r);
73+
buf.flip();
74+
socket.getOutputStream().write(buf.array(), buf.arrayOffset(), buf.remaining());
75+
LOG.infof("Wrote %d bytes to socket", r);
76+
buf.clear();
77+
bytesWritten += r;
78+
}
7579
}
7680
} catch (final ClosedChannelException ignore) {
7781
LOG.info("Channel closed");

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ public void start() {
5959
while (running) {
6060
final SocketChannel channel = serverChannel.accept();
6161
final Socket socket = new Socket(LOCALHOST, httpServerPort);
62-
socket.setSoTimeout(10000);
6362
// Write from socket to channel
6463
Thread.startVirtualThread(createSocketToChannelWriter(byteBufferSize, socket, channel));
6564
// Write from channel to socket

0 commit comments

Comments
 (0)