diff --git a/transport/src/main/java/io/netty/channel/pool/FixedChannelPool.java b/transport/src/main/java/io/netty/channel/pool/FixedChannelPool.java index 4bbf0bbf0e..487ba13859 100644 --- a/transport/src/main/java/io/netty/channel/pool/FixedChannelPool.java +++ b/transport/src/main/java/io/netty/channel/pool/FixedChannelPool.java @@ -258,6 +258,8 @@ public class FixedChannelPool extends SimpleChannelPool { assert executor.inEventLoop(); if (closed) { + // Since the pool is closed, we have no choice but to close the channel + channel.close(); promise.setFailure(new IllegalStateException("FixedChannelPooled was closed")); return; } @@ -366,6 +368,10 @@ public class FixedChannelPool extends SimpleChannelPool { assert executor.inEventLoop(); if (closed) { + if (future.isSuccess()) { + // Since the pool is closed, we have no choice but to close the channel + future.getNow().close(); + } originalPromise.setFailure(new IllegalStateException("FixedChannelPooled was closed")); return; } diff --git a/transport/src/test/java/io/netty/channel/pool/FixedChannelPoolTest.java b/transport/src/test/java/io/netty/channel/pool/FixedChannelPoolTest.java index cfd5c5ed49..21aa03a736 100644 --- a/transport/src/test/java/io/netty/channel/pool/FixedChannelPoolTest.java +++ b/transport/src/test/java/io/netty/channel/pool/FixedChannelPoolTest.java @@ -299,8 +299,12 @@ public class FixedChannelPoolTest { } }).syncUninterruptibly(); pool.release(channel).syncUninterruptibly(); + + // Since the pool is closed.. the release channel should have been closed + channel.closeFuture().syncUninterruptibly(); + assertFalse("Unexpected open channel", channel.isOpen()); + sc.close().syncUninterruptibly(); - channel.close().syncUninterruptibly(); } @Test