diff --git a/deploy/tasks/buildah-oci-ta.yaml b/deploy/tasks/buildah-oci-ta.yaml index f5662a5f3..f25a8d1d2 100644 --- a/deploy/tasks/buildah-oci-ta.yaml +++ b/deploy/tasks/buildah-oci-ta.yaml @@ -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 diff --git a/java-components/domain-proxy/client/src/main/resources/application.properties b/java-components/domain-proxy/client/src/main/resources/application.properties index 5ae321872..9c0d6f0e0 100644 --- a/java-components/domain-proxy/client/src/main/resources/application.properties +++ b/java-components/domain-proxy/client/src/main/resources/application.properties @@ -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 diff --git a/java-components/domain-proxy/common/src/main/java/com/redhat/hacbs/domainproxy/common/CommonIOUtil.java b/java-components/domain-proxy/common/src/main/java/com/redhat/hacbs/domainproxy/common/CommonIOUtil.java index 2f5ce2f56..cc7876be7 100644 --- a/java-components/domain-proxy/common/src/main/java/com/redhat/hacbs/domainproxy/common/CommonIOUtil.java +++ b/java-components/domain-proxy/common/src/main/java/com/redhat/hacbs/domainproxy/common/CommonIOUtil.java @@ -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) { @@ -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); }; @@ -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 { @@ -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); - }; + } } } diff --git a/java-components/domain-proxy/server/src/main/resources/application.properties b/java-components/domain-proxy/server/src/main/resources/application.properties index c6914e176..1eab42a1f 100644 --- a/java-components/domain-proxy/server/src/main/resources/application.properties +++ b/java-components/domain-proxy/server/src/main/resources/application.properties @@ -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}