Skip to content
This repository was archived by the owner on Feb 4, 2022. It is now read-only.

fix(pool): don't try to reconnect if initial connection fails #332

Closed
wants to merge 1 commit into from
Closed
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
10 changes: 5 additions & 5 deletions lib/connection/pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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 {
Expand Down