Suppress setup errors after client.destroy
This allows clients to be destroyed during setupError events without emitting errors from the connect/setup retry loop.
This commit is contained in:
parent
28d3ed86e1
commit
3edf9de578
|
@ -866,23 +866,17 @@ Client.prototype._connect = function _connect() {
|
|||
},
|
||||
unbind: self.unbind.bind(self)
|
||||
};
|
||||
var setupSteps = self.listeners('setup');
|
||||
if (setupSteps.length) {
|
||||
vasync.forEachPipeline({
|
||||
func: function (f, callback) {
|
||||
f(basicClient, callback);
|
||||
},
|
||||
inputs: setupSteps
|
||||
}, function (err, result) {
|
||||
if (err) {
|
||||
// Users may wish to take specific actions if setup steps fail.
|
||||
self.emit('setupError', err);
|
||||
}
|
||||
cb(err, socket);
|
||||
});
|
||||
} else {
|
||||
cb(null, socket);
|
||||
}
|
||||
vasync.forEachPipeline({
|
||||
func: function (f, callback) {
|
||||
f(basicClient, callback);
|
||||
},
|
||||
inputs: self.listeners('setup')
|
||||
}, function (err, res) {
|
||||
if (err) {
|
||||
self.emit('setupError', err);
|
||||
}
|
||||
cb(err);
|
||||
});
|
||||
}
|
||||
|
||||
// Wire up "official" event handlers after successful connect/setup
|
||||
|
@ -937,6 +931,7 @@ Client.prototype._connect = function _connect() {
|
|||
|
||||
retry.on('ready', function (num, delay) {
|
||||
if (self.destroyed) {
|
||||
// Cease connection attempts if destroyed
|
||||
return;
|
||||
}
|
||||
connectSocket(function (err) {
|
||||
|
@ -955,6 +950,10 @@ Client.prototype._connect = function _connect() {
|
|||
});
|
||||
});
|
||||
retry.on('fail', function (err) {
|
||||
if (self.destroyed) {
|
||||
// Silence any connect/setup errors if destroyed
|
||||
return;
|
||||
}
|
||||
self.log.debug('failed to connect after %d attempts', failAfter);
|
||||
// Communicate the last-encountered error
|
||||
if (err instanceof ConnectionError) {
|
||||
|
|
Loading…
Reference in New Issue