Skip to content

Commit ce46d6b

Browse files
authored
perf(cluster): make disconnecting from cluster faster (#721)
This commit will prevent status changes from 'disconnecting' to 'connecting' and will stop connecting to a nodes when disconnecting, which will make disconnecting faster.
1 parent fb27b66 commit ce46d6b

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

lib/cluster/index.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,12 @@ class Cluster extends EventEmitter {
348348
const node = nodes[index]
349349
debug('getting slot cache from %s:%s', node.options.host, node.options.port)
350350
_this.getInfoFromNode(node, function (err) {
351-
if (_this.status === 'end') {
352-
return wrapper(new Error('Cluster is disconnected.'))
351+
switch (_this.status) {
352+
case 'close':
353+
case 'end':
354+
return wrapper(new Error('Cluster is disconnected.'))
355+
case 'disconnecting':
356+
return wrapper(new Error('Cluster is disconnecting.'))
353357
}
354358
if (err) {
355359
_this.emit('node error', err)
@@ -568,6 +572,11 @@ class Cluster extends EventEmitter {
568572
redis.disconnect()
569573
return callback(err)
570574
}
575+
if (this.status === 'disconnecting' || this.status === 'close' || this.status === 'end') {
576+
debug('ignore CLUSTER.SLOTS results (count: %d) since cluster status is %s', result.length, this.status)
577+
callback()
578+
return
579+
}
571580
const nodes = []
572581

573582
debug('cluster slots result count: %d', result.length)

0 commit comments

Comments
 (0)