diff --git a/redisson/src/main/java/org/redisson/pubsub/PublishSubscribeService.java b/redisson/src/main/java/org/redisson/pubsub/PublishSubscribeService.java index c6d2ae531..2430fc469 100644 --- a/redisson/src/main/java/org/redisson/pubsub/PublishSubscribeService.java +++ b/redisson/src/main/java/org/redisson/pubsub/PublishSubscribeService.java @@ -475,7 +475,7 @@ public class PublishSubscribeService { } public CompletableFuture unsubscribeLocked(PubSubType topicType, ChannelName channelName) { - Collection coll = name2entry.remove(channelName); + Collection coll = name2entry.get(channelName); if (coll == null || coll.isEmpty()) { RedisNodeNotFoundException ex = new RedisNodeNotFoundException("Node for name: " + channelName + " hasn't been discovered yet. Check cluster slots coverage using CLUSTER NODES command. Increase value of retryAttempts and/or retryInterval settings."); CompletableFuture promise = new CompletableFuture<>(); @@ -487,6 +487,7 @@ public class PublishSubscribeService { } private CompletableFuture unsubscribeLocked(PubSubType topicType, ChannelName channelName, MasterSlaveEntry msEntry) { + name2entry.remove(channelName); PubSubConnectionEntry entry = name2PubSubConnection.remove(new PubSubKey(channelName, msEntry)); if (entry == null || connectionManager.getServiceManager().isShuttingDown()) { return CompletableFuture.completedFuture(null); @@ -763,7 +764,7 @@ public class PublishSubscribeService { }, timeout, TimeUnit.MILLISECONDS); return sf.thenCompose(res -> { - Collection entries = name2entry.remove(channelName); + Collection entries = name2entry.get(channelName); if (entries == null || entries.isEmpty()) { semaphore.release(); return CompletableFuture.completedFuture(null);