From 0b97b8415ba9ec7653b514350bd753abe3019daf Mon Sep 17 00:00:00 2001 From: Ludovic Orban Date: Mon, 17 May 2021 10:20:42 +0200 Subject: [PATCH] only release connection when channel got released to avoid double connection release race condition Signed-off-by: Ludovic Orban --- .../jetty/http2/client/http/HttpChannelOverHTTP2.java | 4 ++-- .../jetty/http2/client/http/HttpConnectionOverHTTP2.java | 4 +++- jetty-util/src/main/java/org/eclipse/jetty/util/Pool.java | 8 +++++++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/jetty-http2/http2-http-client-transport/src/main/java/org/eclipse/jetty/http2/client/http/HttpChannelOverHTTP2.java b/jetty-http2/http2-http-client-transport/src/main/java/org/eclipse/jetty/http2/client/http/HttpChannelOverHTTP2.java index 9d76ea11979..3bc0904be1e 100644 --- a/jetty-http2/http2-http-client-transport/src/main/java/org/eclipse/jetty/http2/client/http/HttpChannelOverHTTP2.java +++ b/jetty-http2/http2-http-client-transport/src/main/java/org/eclipse/jetty/http2/client/http/HttpChannelOverHTTP2.java @@ -106,8 +106,8 @@ public class HttpChannelOverHTTP2 extends HttpChannel public void release() { setStream(null); - connection.release(this); - getHttpDestination().release(getHttpConnection()); + if (connection.release(this)) + getHttpDestination().release(getHttpConnection()); } @Override diff --git a/jetty-http2/http2-http-client-transport/src/main/java/org/eclipse/jetty/http2/client/http/HttpConnectionOverHTTP2.java b/jetty-http2/http2-http-client-transport/src/main/java/org/eclipse/jetty/http2/client/http/HttpConnectionOverHTTP2.java index a91b876724d..429957eef35 100644 --- a/jetty-http2/http2-http-client-transport/src/main/java/org/eclipse/jetty/http2/client/http/HttpConnectionOverHTTP2.java +++ b/jetty-http2/http2-http-client-transport/src/main/java/org/eclipse/jetty/http2/client/http/HttpConnectionOverHTTP2.java @@ -151,7 +151,7 @@ public class HttpConnectionOverHTTP2 extends HttpConnection implements Sweeper.S return new HttpChannelOverHTTP2(getHttpDestination(), this, getSession()); } - protected void release(HttpChannelOverHTTP2 channel) + protected boolean release(HttpChannelOverHTTP2 channel) { if (LOG.isDebugEnabled()) LOG.debug("Released {}", channel); @@ -162,10 +162,12 @@ public class HttpConnectionOverHTTP2 extends HttpConnection implements Sweeper.S channel.destroy(); else if (isRecycleHttpChannels()) idleChannels.offer(channel); + return true; } else { channel.destroy(); + return false; } } diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/Pool.java b/jetty-util/src/main/java/org/eclipse/jetty/util/Pool.java index e134007419e..cd9d7cf16f9 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/Pool.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/Pool.java @@ -431,7 +431,13 @@ public class Pool implements AutoCloseable, Dumpable // iterate the copy and close its entries for (Entry entry : copy) { - if (entry.tryRemove() && entry.pooled instanceof Closeable) + boolean removed = entry.tryRemove(); + if (!removed) + { + if (LOGGER.isDebugEnabled()) + LOGGER.debug("Pooled object still in use: {}", entry); + } + if (removed && entry.pooled instanceof Closeable) IO.close((Closeable)entry.pooled); } }