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

fix(connection): make pool not try to reconnect forever when reconnectTries = 0 #275

Merged
merged 2 commits into from
Feb 14, 2018
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 lib/connection/pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ function attemptReconnect(self) {
// Count down the number of reconnects
self.retriesLeft = self.retriesLeft - 1;
// How many retries are left
if (self.retriesLeft === 0) {
if (self.retriesLeft <= 0) {
// Destroy the instance
self.destroy();
// Emit close event
Expand Down
23 changes: 23 additions & 0 deletions test/tests/functional/server_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1077,4 +1077,27 @@ describe('Server tests', function() {
}
});
});

it('Should not try to reconnect forever if reconnectTries = 0', {
metadata: { requires: { topology: 'single' } },

test: function(done) {
// Attempt to connect
let server = new Server({
host: 'doesntexist',
bson: new Bson(),
reconnectTries: 0
});

// Add event listeners
server.on('error', function() {});

// Start connection
server.connect();

server.s.pool.on('reconnectFailed', function() {
done();
});
}
});
});