Unsubscribe only once on Subscription.close().
We now unsubscribe from Redis only once when closing a Subscription object to avoid duplicate traffic and unexpected Redis responses. Jedis does not have a mechanism to consume the additional unsubscribe response which leaves protocol frames on the InputStream leading to a corrupt state. Closes #2355
This commit is contained in:
@@ -38,6 +38,7 @@ class JedisSubscription extends AbstractSubscription {
|
||||
|
||||
@Override
|
||||
protected void doClose() {
|
||||
|
||||
if (!getChannels().isEmpty()) {
|
||||
jedisPubSub.unsubscribe();
|
||||
}
|
||||
|
||||
@@ -76,10 +76,6 @@ public class LettuceSubscription extends AbstractSubscription {
|
||||
@Override
|
||||
protected void doClose() {
|
||||
|
||||
if (!isAlive()) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<CompletableFuture<?>> futures = new ArrayList<>();
|
||||
|
||||
if (!getChannels().isEmpty()) {
|
||||
|
||||
@@ -99,8 +99,19 @@ public abstract class AbstractSubscription implements Subscription {
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
doClose();
|
||||
alive.set(false);
|
||||
|
||||
if (alive.compareAndSet(true, false)) {
|
||||
|
||||
doClose();
|
||||
|
||||
synchronized (channels) {
|
||||
channels.clear();
|
||||
}
|
||||
|
||||
synchronized (patterns) {
|
||||
patterns.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user