Skip to content

Commit 4559fb5

Browse files
committed
Synchronise when closing socket and channel and revert buffer size.
1 parent c549cb8 commit 4559fb5

File tree

4 files changed

+23
-22
lines changed

4 files changed

+23
-22
lines changed

deploy/tasks/buildah-oci-ta.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ spec:
142142
- name: BYTE_BUFFER_SIZE
143143
description: The byte buffer size to use for the domain proxy.
144144
type: string
145-
default: 2048
145+
default: 1024
146146
- name: PROXY_TARGET_WHITELIST
147147
description: Comma separated whitelist of target hosts for the domain proxy.
148148
type: string
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
client-domain-socket=${DOMAIN_SOCKET:/tmp/domain-server}
22
client-http-port=8080
3-
byte-buffer-size=${BYTE_BUFFER_SIZE:2048}
3+
byte-buffer-size=${BYTE_BUFFER_SIZE:1024}
44
quarkus.log.min-level=ALL
55
quarkus.log.level=ALL
66
quarkus.log.console.format=%d{yyyy-MM-dd HH:mm:ss,SSS} [Domain Proxy Client] %-5p [%c{3.}] (%t) %s%e%n

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

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
public final class CommonIOUtil {
1414

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

1718
public static Runnable createSocketToChannelWriter(final int byteBufferSize, final Socket socket,
1819
final SocketChannel channel) {
@@ -39,16 +40,7 @@ public static Runnable createSocketToChannelWriter(final int byteBufferSize, fin
3940
} catch (final IOException e) {
4041
LOG.errorf(e, "Error writing from socket to channel");
4142
} finally {
42-
try {
43-
channel.close();
44-
} catch (final IOException e) {
45-
LOG.errorf(e, "Error closing channel");
46-
}
47-
try {
48-
socket.close();
49-
} catch (final IOException e) {
50-
LOG.errorf(e, "Error closing socket");
51-
}
43+
closeSocketAndChannel(socket, channel);
5244
}
5345
LOG.infof("Wrote %d bytes from socket to channel", bytesWritten);
5446
};
@@ -61,7 +53,6 @@ public static Runnable createChannelToSocketWriter(final int byteBufferSize, fin
6153
Thread.currentThread().setName("ChannelToSocketWriter");
6254
int r;
6355
final ByteBuffer buf = ByteBuffer.allocate(byteBufferSize);
64-
buf.clear();
6556
int bytesWritten = 0;
6657
LOG.info("Writing from channel to socket");
6758
try {
@@ -82,18 +73,28 @@ public static Runnable createChannelToSocketWriter(final int byteBufferSize, fin
8273
} catch (final IOException e) {
8374
LOG.errorf(e, "Error writing from channel to socket");
8475
} finally {
85-
try {
76+
closeSocketAndChannel(socket, channel);
77+
}
78+
LOG.infof("Wrote %d bytes from channel to socket", bytesWritten);
79+
};
80+
}
81+
82+
private static void closeSocketAndChannel(final Socket socket, final SocketChannel channel) {
83+
synchronized (CLOSE_LOCK) {
84+
try {
85+
if (channel != null && channel.isOpen()) {
8686
channel.close();
87-
} catch (final IOException e) {
88-
LOG.errorf(e, "Error closing channel");
8987
}
90-
try {
88+
} catch (final IOException e) {
89+
LOG.errorf(e, "Error closing channel");
90+
}
91+
try {
92+
if (socket != null && !socket.isClosed()) {
9193
socket.close();
92-
} catch (final IOException e) {
93-
LOG.errorf(e, "Error closing socket");
9494
}
95+
} catch (final IOException e) {
96+
LOG.errorf(e, "Error closing socket");
9597
}
96-
LOG.infof("Wrote %d bytes from channel to socket", bytesWritten);
97-
};
98+
}
9899
}
99100
}

java-components/domain-proxy/server/src/main/resources/application.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
server-domain-socket=${DOMAIN_SOCKET:/tmp/domain-server}
22
server-http-port=2000
3-
byte-buffer-size=${BYTE_BUFFER_SIZE:2048}
3+
byte-buffer-size=${BYTE_BUFFER_SIZE:1024}
44
proxy-target-whitelist=${PROXY_TARGET_WHITELIST:repo.maven.apache.org,repository.jboss.org,packages.confluent.io,jitpack.io,repo.gradle.org,plugins.gradle.org}
55
quarkus.rest-client.proxy-address=${INTERNAL_PROXY_ADDRESS:indy-generic-proxy:80}
66
quarkus.rest-client.proxy-user=${INTERNAL_PROXY_USER}

0 commit comments

Comments
 (0)