From bec6ee4d4dd1b805220965c67847180254d5a908 Mon Sep 17 00:00:00 2001 From: Nikita Date: Wed, 14 Sep 2016 15:17:55 +0300 Subject: [PATCH] failed connection should be closed --- .../connection/pool/ConnectionPool.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/redisson/src/main/java/org/redisson/connection/pool/ConnectionPool.java b/redisson/src/main/java/org/redisson/connection/pool/ConnectionPool.java index 14065be65..6ac025101 100644 --- a/redisson/src/main/java/org/redisson/connection/pool/ConnectionPool.java +++ b/redisson/src/main/java/org/redisson/connection/pool/ConnectionPool.java @@ -41,6 +41,13 @@ import io.netty.util.TimerTask; import io.netty.util.concurrent.Future; import io.netty.util.concurrent.FutureListener; +/** + * Base connection pool class + * + * @author Nikita Koksharov + * + * @param - connection type + */ abstract class ConnectionPool { private final Logger log = LoggerFactory.getLogger(getClass()); @@ -211,8 +218,6 @@ abstract class ConnectionPool { @Override public void operationComplete(Future future) throws Exception { if (!future.isSuccess()) { - releaseConnection(entry); - promiseFailure(entry, promise, future.cause()); return; } @@ -223,13 +228,13 @@ abstract class ConnectionPool { return; } - promiseSuccessful(entry, promise, conn); + connectedSuccessful(entry, promise, conn); } }); return promise; } - private void promiseSuccessful(ClientConnectionsEntry entry, RPromise promise, T conn) { + private void connectedSuccessful(ClientConnectionsEntry entry, RPromise promise, T conn) { entry.resetFailedAttempts(); if (!promise.trySuccess(conn)) { releaseConnection(entry, conn); @@ -247,15 +252,20 @@ abstract class ConnectionPool { checkForReconnect(entry); } + releaseConnection(entry); + promise.tryFailure(cause); } private void promiseFailure(ClientConnectionsEntry entry, RPromise promise, T conn) { int attempts = entry.incFailedAttempts(); if (attempts == config.getFailedAttempts()) { + conn.closeAsync(); checkForReconnect(entry); } else if (attempts < config.getFailedAttempts()) { releaseConnection(entry, conn); + } else { + conn.closeAsync(); } releaseConnection(entry); @@ -267,9 +277,12 @@ abstract class ConnectionPool { private RFuture promiseFailure(ClientConnectionsEntry entry, T conn) { int attempts = entry.incFailedAttempts(); if (attempts == config.getFailedAttempts()) { + conn.closeAsync(); checkForReconnect(entry); } else if (attempts < config.getFailedAttempts()) { releaseConnection(entry, conn); + } else { + conn.closeAsync(); } releaseConnection(entry);