From 4a70e661b1c29808b9a078399ac25bf0a2d79f75 Mon Sep 17 00:00:00 2001 From: Maxim Nesen Date: Mon, 19 Oct 2020 07:56:26 +0200 Subject: [PATCH] NettyConnector connection close Signed-off-by: Maxim Nesen --- .../glassfish/jersey/netty/connector/NettyConnector.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/connectors/netty-connector/src/main/java/org/glassfish/jersey/netty/connector/NettyConnector.java b/connectors/netty-connector/src/main/java/org/glassfish/jersey/netty/connector/NettyConnector.java index d13c86dae3..c2fdf410a5 100644 --- a/connectors/netty-connector/src/main/java/org/glassfish/jersey/netty/connector/NettyConnector.java +++ b/connectors/netty-connector/src/main/java/org/glassfish/jersey/netty/connector/NettyConnector.java @@ -261,6 +261,7 @@ protected void initChannel(SocketChannel ch) throws Exception { if (th == null) { ch.pipeline().addLast(INACTIVE_POOLED_CONNECTION_HANDLER, new IdleStateHandler(0, 0, maxPoolIdle)); ch.pipeline().addLast(PRUNE_INACTIVE_POOL, new PruneIdlePool(connections, key)); + boolean added = true; synchronized (connections) { ArrayList conns1 = connections.get(key); if (conns1 == null) { @@ -271,10 +272,16 @@ protected void initChannel(SocketChannel ch) throws Exception { synchronized (conns1) { if (conns1.size() < maxPoolSize) { conns1.add(ch); - } // else do not add the Channel to the idle pool + } else { // else do not add the Channel to the idle pool + added = false; + } } } } + + if (!added) { + ch.close(); + } } else { ch.close(); // if responseAvailable has been completed, no-op: jersey will encounter IOException while reading response body