From 1f3bae78c5823d2e3c43ba0666f889e3850df34a Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Tue, 19 Jul 2016 20:55:44 +0200 Subject: [PATCH] [#5553] SimpleChannelPool#notifyConnect() may leak Channels Motivation: The SimpleChannelPool#notifyConnect() method will leak Channels if the user cancelled the Promise in between. Modifications: Release the channel if the Promise was complete before. Result: No more channel leaks. --- .../java/io/netty/channel/pool/SimpleChannelPool.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/transport/src/main/java/io/netty/channel/pool/SimpleChannelPool.java b/transport/src/main/java/io/netty/channel/pool/SimpleChannelPool.java index b61c13f088..1d4fee3edf 100644 --- a/transport/src/main/java/io/netty/channel/pool/SimpleChannelPool.java +++ b/transport/src/main/java/io/netty/channel/pool/SimpleChannelPool.java @@ -154,9 +154,13 @@ public class SimpleChannelPool implements ChannelPool { return promise; } - private static void notifyConnect(ChannelFuture future, Promise promise) { + private void notifyConnect(ChannelFuture future, Promise promise) { if (future.isSuccess()) { - promise.setSuccess(future.channel()); + Channel channel = future.channel(); + if (!promise.trySuccess(channel)) { + // Promise was completed in the meantime (like cancelled), just release the channel again + release(channel); + } } else { promise.setFailure(future.cause()); }