1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-06 02:15:48 +03:00

fix(clustered pubsub): check that client.isOpen before calling client.disconnect() when unsubscribing (#2687)

* Confirm the client isOpen before disconnecting

* Write tests

* fix tests

* fix tests

---------

Co-authored-by: Leibale Eidelman <me@leibale.com>
This commit is contained in:
Brent Layne
2024-01-29 03:25:26 -05:00
committed by GitHub
parent 5a96058c2f
commit 295647cf9d
2 changed files with 29 additions and 2 deletions

View File

@@ -562,7 +562,7 @@ export default class RedisClusterSlots<
const client = await this.getPubSubClient();
await unsubscribe(client);
if (!client.isPubSubActive) {
if (!client.isPubSubActive && client.isOpen) {
await client.disconnect();
this.pubSubNode = undefined;
}
@@ -613,7 +613,7 @@ export default class RedisClusterSlots<
const client = await master.pubSubClient;
await unsubscribe(client);
if (!client.isPubSubActive) {
if (!client.isPubSubActive && client.isOpen) {
await client.disconnect();
master.pubSubClient = undefined;
}

View File

@@ -235,6 +235,18 @@ describe('Cluster', () => {
assert.equal(cluster.pubSubNode, undefined);
}, GLOBAL.CLUSTERS.OPEN);
testUtils.testWithCluster('concurrent UNSUBSCRIBE does not throw an error (#2685)', async cluster => {
const listener = spy();
await Promise.all([
cluster.subscribe('1', listener),
cluster.subscribe('2', listener)
]);
await Promise.all([
cluster.unsubscribe('1', listener),
cluster.unsubscribe('2', listener)
]);
}, GLOBAL.CLUSTERS.OPEN);
testUtils.testWithCluster('psubscribe & punsubscribe', async cluster => {
const listener = spy();
@@ -323,6 +335,21 @@ describe('Cluster', () => {
minimumDockerVersion: [7]
});
testUtils.testWithCluster('concurrent SUNSUBCRIBE does not throw an error (#2685)', async cluster => {
const listener = spy();
await Promise.all([
await cluster.sSubscribe('1', listener),
await cluster.sSubscribe('2', listener)
]);
await Promise.all([
cluster.sUnsubscribe('1', listener),
cluster.sUnsubscribe('2', listener)
]);
}, {
...GLOBAL.CLUSTERS.OPEN,
minimumDockerVersion: [7]
});
testUtils.testWithCluster('should handle sharded-channel-moved events', async cluster => {
const SLOT = 10328,
migrating = cluster.slots[SLOT].master,