From 7a9b0a184d337c6550469afb751b7beff007236f Mon Sep 17 00:00:00 2001 From: Nikita Koksharov Date: Wed, 27 Dec 2023 15:00:04 +0300 Subject: [PATCH] Fixed - IllegalReferenceCountException is thrown when canceling a method call. #5519 --- .../org/redisson/command/RedisExecutor.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/redisson/src/main/java/org/redisson/command/RedisExecutor.java b/redisson/src/main/java/org/redisson/command/RedisExecutor.java index 2b2b70c9a..6078652cc 100644 --- a/redisson/src/main/java/org/redisson/command/RedisExecutor.java +++ b/redisson/src/main/java/org/redisson/command/RedisExecutor.java @@ -132,20 +132,20 @@ public class RedisExecutor { return; } - if (connectionFuture.cancel(false)) { + if (connectionFuture.completeExceptionally(new CancellationException())) { log.debug("Connection obtaining canceled for {}", command); timeout.ifPresent(Timeout::cancel); - if (attemptPromise.cancel(false)) { + if (attemptPromise.completeExceptionally(new CancellationException())) { free(); } } else { if (command.isBlockingCommand()) { RedisConnection c = connectionFuture.getNow(null); if (writeFuture.cancel(false)) { - attemptPromise.cancel(false); + attemptPromise.completeExceptionally(new CancellationException()); } else { c.forceFastReconnectAsync().whenComplete((res, ex) -> { - attemptPromise.cancel(true); + attemptPromise.completeExceptionally(new CancellationException()); }); } } @@ -212,7 +212,7 @@ public class RedisExecutor { timeout.ifPresent(Timeout::cancel); TimerTask task = timeout -> { - if (connectionFuture.cancel(false)) { + if (connectionFuture.completeExceptionally(new CancellationException())) { exception = new RedisTimeoutException("Unable to acquire connection! " + this.connectionFuture + "Increase connection pool size or timeout. " + "Node source: " + source @@ -261,7 +261,7 @@ public class RedisExecutor { return; } - if (connectionFuture.cancel(false)) { + if (connectionFuture.completeExceptionally(new CancellationException())) { exception = new RedisTimeoutException("Unable to acquire connection! " + connectionFuture + "Increase connection pool size. " + "Node source: " + source @@ -297,7 +297,7 @@ public class RedisExecutor { } if (mainPromise.isCancelled()) { - if (attemptPromise.cancel(false)) { + if (attemptPromise.completeExceptionally(new CancellationException())) { free(); } return; @@ -310,7 +310,7 @@ public class RedisExecutor { } return; } - if (!attemptPromise.cancel(false)) { + if (!attemptPromise.completeExceptionally(new CancellationException())) { return; } @@ -407,7 +407,7 @@ public class RedisExecutor { long timeoutAmount = timeoutTime; TimerTask timeoutResponseTask = timeout -> { if (isResendAllowed(attempt, attempts)) { - if (!attemptPromise.cancel(false)) { + if (!attemptPromise.completeExceptionally(new CancellationException())) { return; } @@ -469,7 +469,7 @@ public class RedisExecutor { && !attemptPromise.isDone()) { log.debug("Canceled blocking operation {} used {}", command, connection); connection.forceFastReconnectAsync().whenComplete((r, ex) -> { - attemptPromise.cancel(true); + attemptPromise.completeExceptionally(new CancellationException()); }); return; }