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 92f6eabb26
commit 0b97b8415b
3 changed files with 12 additions and 4 deletions

View File

@ -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

View File

@ -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;
}
}

View File

@ -431,7 +431,13 @@ public class Pool<T> 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);
}
}