only release connection when channel got released to avoid double connection release race condition

Signed-off-by: Ludovic Orban <lorban@bitronix.be>
This commit is contained in:
Ludovic Orban 2021-05-17 10:20:42 +02:00
parent 97a2a9993f
commit 593f4225f8
3 changed files with 12 additions and 4 deletions

View File

@ -102,7 +102,7 @@ public class HttpChannelOverHTTP2 extends HttpChannel
public void release() public void release()
{ {
setStream(null); setStream(null);
connection.release(this); if (connection.release(this))
getHttpDestination().release(getHttpConnection()); getHttpDestination().release(getHttpConnection());
} }

View File

@ -100,7 +100,7 @@ public class HttpConnectionOverHTTP2 extends HttpConnection implements Sweeper.S
return new HttpChannelOverHTTP2(getHttpDestination(), this, getSession()); return new HttpChannelOverHTTP2(getHttpDestination(), this, getSession());
} }
protected void release(HttpChannelOverHTTP2 channel) protected boolean release(HttpChannelOverHTTP2 channel)
{ {
if (LOG.isDebugEnabled()) if (LOG.isDebugEnabled())
LOG.debug("Released {}", channel); LOG.debug("Released {}", channel);
@ -111,10 +111,12 @@ public class HttpConnectionOverHTTP2 extends HttpConnection implements Sweeper.S
channel.destroy(); channel.destroy();
else if (isRecycleHttpChannels()) else if (isRecycleHttpChannels())
idleChannels.offer(channel); idleChannels.offer(channel);
return true;
} }
else else
{ {
channel.destroy(); channel.destroy();
return false;
} }
} }

View File

@ -461,7 +461,13 @@ public class Pool<T> implements AutoCloseable, Dumpable
// iterate the copy and close its entries // iterate the copy and close its entries
for (Entry entry : copy) 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); IO.close((Closeable)entry.pooled);
} }
} }