Skip to content

Commit

Permalink
perf(cluster): make disconnecting from cluster faster (#721)
Browse files Browse the repository at this point in the history
This commit will prevent status changes from 'disconnecting'
to 'connecting' and will stop connecting to a nodes
when disconnecting, which will make disconnecting faster.
  • Loading branch information
luin committed Oct 15, 2018
1 parent fb27b66 commit ce46d6b
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/cluster/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,12 @@ class Cluster extends EventEmitter {
const node = nodes[index]
debug('getting slot cache from %s:%s', node.options.host, node.options.port)
_this.getInfoFromNode(node, function (err) {
if (_this.status === 'end') {
return wrapper(new Error('Cluster is disconnected.'))
switch (_this.status) {
case 'close':
case 'end':
return wrapper(new Error('Cluster is disconnected.'))
case 'disconnecting':
return wrapper(new Error('Cluster is disconnecting.'))
}
if (err) {
_this.emit('node error', err)
Expand Down Expand Up @@ -568,6 +572,11 @@ class Cluster extends EventEmitter {
redis.disconnect()
return callback(err)
}
if (this.status === 'disconnecting' || this.status === 'close' || this.status === 'end') {
debug('ignore CLUSTER.SLOTS results (count: %d) since cluster status is %s', result.length, this.status)
callback()
return
}
const nodes = []

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

0 comments on commit ce46d6b

Please sign in to comment.