diff --git a/lib/connection/pool.js b/lib/connection/pool.js index 5d044c652..2b41a178b 100644 --- a/lib/connection/pool.js +++ b/lib/connection/pool.js @@ -273,7 +273,7 @@ function reauthenticate(pool, connection, cb) { authenticateAgainstProvider(pool, connection, Object.keys(pool.authProviders), cb); } -function connectionFailureHandler(self, event) { +function connectionFailureHandler(self, event, skipReconnect) { return function(err) { if (this._connectionFailHandled) return; this._connectionFailHandled = true; @@ -317,7 +317,7 @@ function connectionFailureHandler(self, event) { } // Start reconnection attempts - if (!self.reconnectId && self.options.reconnect) { + if (!self.reconnectId && self.options.reconnect && !skipReconnect) { self.reconnectId = setTimeout(attemptReconnect(self), self.options.reconnectInterval); } @@ -759,9 +759,9 @@ Pool.prototype.connect = function() { }); // Add error handlers - connection.once('error', connectionFailureHandler(this, 'error')); - connection.once('close', connectionFailureHandler(this, 'close')); - connection.once('timeout', connectionFailureHandler(this, 'timeout')); + connection.once('error', connectionFailureHandler(this, 'error', true)); + connection.once('close', connectionFailureHandler(this, 'close', true)); + connection.once('timeout', connectionFailureHandler(this, 'timeout', true)); connection.once('parseError', connectionFailureHandler(this, 'parseError')); try {