[#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.
This commit is contained in:
Norman Maurer 2016-07-19 20:55:44 +02:00
parent 42de9d446f
commit 1f3bae78c5

View File

@ -154,9 +154,13 @@ public class SimpleChannelPool implements ChannelPool {
return promise; return promise;
} }
private static void notifyConnect(ChannelFuture future, Promise<Channel> promise) { private void notifyConnect(ChannelFuture future, Promise<Channel> promise) {
if (future.isSuccess()) { 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 { } else {
promise.setFailure(future.cause()); promise.setFailure(future.cause());
} }