From 33e5b5872b098c13cf1bbf70f8152f7f3d94dc7c Mon Sep 17 00:00:00 2001 From: Nikita Koksharov Date: Thu, 23 Sep 2021 08:57:23 +0300 Subject: [PATCH] Fixed - don't PING connection which is in use --- .../client/handler/PingConnectionHandler.java | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/redisson/src/main/java/org/redisson/client/handler/PingConnectionHandler.java b/redisson/src/main/java/org/redisson/client/handler/PingConnectionHandler.java index bedbdc0f7..78c534ff4 100644 --- a/redisson/src/main/java/org/redisson/client/handler/PingConnectionHandler.java +++ b/redisson/src/main/java/org/redisson/client/handler/PingConnectionHandler.java @@ -66,23 +66,21 @@ public class PingConnectionHandler extends ChannelInboundHandlerAdapter { future = null; } - config.getTimer().newTimeout(new TimerTask() { - @Override - public void run(Timeout timeout) throws Exception { - if (connection.isClosed() || ctx.isRemoved()) { - return; - } + config.getTimer().newTimeout(timeout -> { + if (connection.isClosed() || ctx.isRemoved()) { + return; + } - if (future != null + if (connection.getUsage() == 0 + && future != null && (future.cancel(false) || !future.isSuccess())) { - ctx.channel().close(); - if (future.cause() != null && !future.isCancelled()) { - log.error("Unable to send PING command over channel: " + ctx.channel(), future.cause()); - } - log.debug("channel: {} closed due to PING response timeout set in {} ms", ctx.channel(), config.getPingConnectionInterval()); - } else { - sendPing(ctx); + ctx.channel().close(); + if (future.cause() != null && !future.isCancelled()) { + log.error("Unable to send PING command over channel: " + ctx.channel(), future.cause()); } + log.debug("channel: {} closed due to PING response timeout set in {} ms", ctx.channel(), config.getPingConnectionInterval()); + } else { + sendPing(ctx); } }, config.getPingConnectionInterval(), TimeUnit.MILLISECONDS); }