From 593f4225f8639fa825f4ea6b9fa4b2c959e6862d 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 c1797b62ece..804adccad71 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 @@ -102,8 +102,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 ceff287a3f5..b7dbad78bde 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 @@ -100,7 +100,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); @@ -111,10 +111,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 d481eb18236..ba20f2235a8 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 @@ -461,7 +461,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); } }