From d982772a81b154eb58e75fbcd062e0796bb153bd Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Mon, 10 May 2021 16:22:02 +0200 Subject: [PATCH] Avoid ClassCastException by inspecting endpoint type when closing ClusterDistributionChannelWriter #1706 --- .../cluster/ClusterDistributionChannelWriter.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/lettuce/core/cluster/ClusterDistributionChannelWriter.java b/src/main/java/io/lettuce/core/cluster/ClusterDistributionChannelWriter.java index 776728c8e3..5d10fc7982 100644 --- a/src/main/java/io/lettuce/core/cluster/ClusterDistributionChannelWriter.java +++ b/src/main/java/io/lettuce/core/cluster/ClusterDistributionChannelWriter.java @@ -28,6 +28,7 @@ import java.util.stream.IntStream; import io.lettuce.core.ClientOptions; +import io.lettuce.core.CommandListenerWriter; import io.lettuce.core.ReadFrom; import io.lettuce.core.RedisChannelHandler; import io.lettuce.core.RedisChannelWriter; @@ -425,7 +426,16 @@ public CompletableFuture closeAsync() { } public void disconnectDefaultEndpoint() { - ((DefaultEndpoint) defaultWriter).disconnect(); + + DefaultEndpoint defaultEndpoint; + + if (defaultWriter instanceof CommandListenerWriter) { + defaultEndpoint = (DefaultEndpoint) ((CommandListenerWriter) defaultWriter).getDelegate(); + } else { + defaultEndpoint = ((DefaultEndpoint) defaultWriter); + } + + defaultEndpoint.disconnect(); } @Override