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:
Patrick Mooney 2014-06-26 11:45:05 -05:00
parent 28d3ed86e1
commit 3edf9de578
1 changed files with 16 additions and 17 deletions

View File

@ -866,23 +866,17 @@ Client.prototype._connect = function _connect() {
}, },
unbind: self.unbind.bind(self) unbind: self.unbind.bind(self)
}; };
var setupSteps = self.listeners('setup');
if (setupSteps.length) {
vasync.forEachPipeline({ vasync.forEachPipeline({
func: function (f, callback) { func: function (f, callback) {
f(basicClient, callback); f(basicClient, callback);
}, },
inputs: setupSteps inputs: self.listeners('setup')
}, function (err, result) { }, function (err, res) {
if (err) { if (err) {
// Users may wish to take specific actions if setup steps fail.
self.emit('setupError', err); self.emit('setupError', err);
} }
cb(err, socket); cb(err);
}); });
} else {
cb(null, socket);
}
} }
// Wire up "official" event handlers after successful connect/setup // Wire up "official" event handlers after successful connect/setup
@ -937,6 +931,7 @@ Client.prototype._connect = function _connect() {
retry.on('ready', function (num, delay) { retry.on('ready', function (num, delay) {
if (self.destroyed) { if (self.destroyed) {
// Cease connection attempts if destroyed
return; return;
} }
connectSocket(function (err) { connectSocket(function (err) {
@ -955,6 +950,10 @@ Client.prototype._connect = function _connect() {
}); });
}); });
retry.on('fail', function (err) { 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); self.log.debug('failed to connect after %d attempts', failAfter);
// Communicate the last-encountered error // Communicate the last-encountered error
if (err instanceof ConnectionError) { if (err instanceof ConnectionError) {