Skip to content

Commit

Permalink
Avoid ClassCastException by inspecting endpoint type when closing Clu…
Browse files Browse the repository at this point in the history
…sterDistributionChannelWriter #1706
  • Loading branch information
mp911de committed May 10, 2021
1 parent b0f6f5b commit d982772
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -425,7 +426,16 @@ public CompletableFuture<Void> 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
Expand Down

0 comments on commit d982772

Please sign in to comment.