From bd42987143958b4a5232f76229b914249a51cddf Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Mon, 20 Jul 2015 14:48:27 +0200 Subject: [PATCH] [#3988] Correctly count acquired channels in FixedChannelPool Motivation: We missed to correctly count acquired channels in FixedChannelPool which could produce an assert error. Modifications: Only try to decrement acquired count if the channel was really acuired. Result: No more assert error possible. --- .../netty/channel/pool/FixedChannelPool.java | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) 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 5c08ac6260..f23c5404eb 100644 --- a/transport/src/main/java/io/netty/channel/pool/FixedChannelPool.java +++ b/transport/src/main/java/io/netty/channel/pool/FixedChannelPool.java @@ -271,6 +271,8 @@ public final class FixedChannelPool extends SimpleChannelPool { timeoutFuture.cancel(false); } + task.acquired(); + --pendingAcquireCount; ++acquiredChannelCount; @@ -289,7 +291,7 @@ public final class FixedChannelPool extends SimpleChannelPool { ScheduledFuture timeoutFuture; public AcquireTask(Promise promise) { - super(promise); + super(promise, false); // We need to create a new promise as we need to ensure the AcquireListener runs in the correct // EventLoop. this.promise = executor.newPromise().addListener(this); @@ -322,9 +324,15 @@ public final class FixedChannelPool extends SimpleChannelPool { private class AcquireListener implements FutureListener { private final Promise originalPromise; + protected boolean acquired; AcquireListener(Promise originalPromise) { + this(originalPromise, true); + } + + protected AcquireListener(Promise originalPromise, boolean acquired) { this.originalPromise = originalPromise; + this.acquired = acquired; } @Override @@ -334,11 +342,19 @@ public final class FixedChannelPool extends SimpleChannelPool { if (future.isSuccess()) { originalPromise.setSuccess(future.getNow()); } else { - // Something went wrong try to run pending acquire tasks. - decrementAndRunTaskQueue(); + if (acquired) { + decrementAndRunTaskQueue(); + } else { + runTaskQueue(); + } + originalPromise.setFailure(future.cause()); } } + + public void acquired() { + acquired = true; + } } @Override