Skip to content

Commit

Permalink
Synchronise when closing socket and channel and revert buffer size.
Browse files Browse the repository at this point in the history
  • Loading branch information
tecarter94 committed Nov 11, 2024
1 parent c549cb8 commit 4559fb5
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 22 deletions.
2 changes: 1 addition & 1 deletion deploy/tasks/buildah-oci-ta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ spec:
- name: BYTE_BUFFER_SIZE
description: The byte buffer size to use for the domain proxy.
type: string
default: 2048
default: 1024
- name: PROXY_TARGET_WHITELIST
description: Comma separated whitelist of target hosts for the domain proxy.
type: string
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
client-domain-socket=${DOMAIN_SOCKET:/tmp/domain-server}
client-http-port=8080
byte-buffer-size=${BYTE_BUFFER_SIZE:2048}
byte-buffer-size=${BYTE_BUFFER_SIZE:1024}
quarkus.log.min-level=ALL
quarkus.log.level=ALL
quarkus.log.console.format=%d{yyyy-MM-dd HH:mm:ss,SSS} [Domain Proxy Client] %-5p [%c{3.}] (%t) %s%e%n
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
public final class CommonIOUtil {

private static final Logger LOG = Logger.getLogger(CommonIOUtil.class);
private static final Object CLOSE_LOCK = new Object();

public static Runnable createSocketToChannelWriter(final int byteBufferSize, final Socket socket,
final SocketChannel channel) {
Expand All @@ -39,16 +40,7 @@ public static Runnable createSocketToChannelWriter(final int byteBufferSize, fin
} catch (final IOException e) {
LOG.errorf(e, "Error writing from socket to channel");
} finally {
try {
channel.close();
} catch (final IOException e) {
LOG.errorf(e, "Error closing channel");
}
try {
socket.close();
} catch (final IOException e) {
LOG.errorf(e, "Error closing socket");
}
closeSocketAndChannel(socket, channel);
}
LOG.infof("Wrote %d bytes from socket to channel", bytesWritten);
};
Expand All @@ -61,7 +53,6 @@ public static Runnable createChannelToSocketWriter(final int byteBufferSize, fin
Thread.currentThread().setName("ChannelToSocketWriter");
int r;
final ByteBuffer buf = ByteBuffer.allocate(byteBufferSize);
buf.clear();
int bytesWritten = 0;
LOG.info("Writing from channel to socket");
try {
Expand All @@ -82,18 +73,28 @@ public static Runnable createChannelToSocketWriter(final int byteBufferSize, fin
} catch (final IOException e) {
LOG.errorf(e, "Error writing from channel to socket");
} finally {
try {
closeSocketAndChannel(socket, channel);
}
LOG.infof("Wrote %d bytes from channel to socket", bytesWritten);
};
}

private static void closeSocketAndChannel(final Socket socket, final SocketChannel channel) {
synchronized (CLOSE_LOCK) {
try {
if (channel != null && channel.isOpen()) {
channel.close();
} catch (final IOException e) {
LOG.errorf(e, "Error closing channel");
}
try {
} catch (final IOException e) {
LOG.errorf(e, "Error closing channel");
}
try {
if (socket != null && !socket.isClosed()) {
socket.close();
} catch (final IOException e) {
LOG.errorf(e, "Error closing socket");
}
} catch (final IOException e) {
LOG.errorf(e, "Error closing socket");
}
LOG.infof("Wrote %d bytes from channel to socket", bytesWritten);
};
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
server-domain-socket=${DOMAIN_SOCKET:/tmp/domain-server}
server-http-port=2000
byte-buffer-size=${BYTE_BUFFER_SIZE:2048}
byte-buffer-size=${BYTE_BUFFER_SIZE:1024}
proxy-target-whitelist=${PROXY_TARGET_WHITELIST:repo.maven.apache.org,repository.jboss.org,packages.confluent.io,jitpack.io,repo.gradle.org,plugins.gradle.org}
quarkus.rest-client.proxy-address=${INTERNAL_PROXY_ADDRESS:indy-generic-proxy:80}
quarkus.rest-client.proxy-user=${INTERNAL_PROXY_USER}
Expand Down

0 comments on commit 4559fb5

Please sign in to comment.