Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add second arg to "node error" to know which node failed #793

Merged
merged 3 commits into from
Feb 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ reconnecting | emits after `close` when a reconnection will be made. The argumen
end | emits after `close` when no more reconnections will be made.
+node | emits when a new node is connected.
-node | emits when a node is disconnected.
node error | emits when an error occurs when connecting to a node
node error | emits when an error occurs when connecting to a node. The second argument indicates the address of the node.

### Password
Setting the `password` option to access password-protected clusters:
Expand Down
9 changes: 5 additions & 4 deletions lib/cluster/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ class Cluster extends EventEmitter {
this.connectionPool.on('drain', () => {
this.setStatus('close')
})
this.connectionPool.on('nodeError', (error) => {
this.emit('node error', error)
this.connectionPool.on('nodeError', (error, key) => {
this.emit('node error', error, key)
})

this.subscriber = new ClusterSubscriber(this.connectionPool, this)
Expand Down Expand Up @@ -374,7 +374,8 @@ class Cluster extends EventEmitter {
return wrapper(error)
}
const node = nodes[index]
debug('getting slot cache from %s:%s', node.options.host, node.options.port)
const key = `${node.options.host}:${node.options.port}`
debug('getting slot cache from %s', key)
_this.getInfoFromNode(node, function (err) {
switch (_this.status) {
case 'close':
Expand All @@ -384,7 +385,7 @@ class Cluster extends EventEmitter {
return wrapper(new Error('Cluster is disconnecting.'))
}
if (err) {
_this.emit('node error', err)
_this.emit('node error', err, key)
lastNodeError = err
tryNode(index + 1)
} else {
Expand Down
3 changes: 2 additions & 1 deletion test/functional/cluster/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,9 @@ describe('cluster:connect', function () {
}
});

cluster.once('node error', function (err) {
cluster.once('node error', function (err, key) {
expect(err.message).to.eql(errorMessage);
expect(['127.0.0.1:30001', '127.0.0.1:30002']).to.include(key)
checkDone();
});

Expand Down
1 change: 0 additions & 1 deletion test/mocha.opts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
--reporter spec
--recursive
--growl