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

Commit

Permalink
fix(connection): make pool not try to reconnect forever when reconnec…
Browse files Browse the repository at this point in the history
…tTries = 0 (#275)

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

* test(server): add test coverage for #275

Re: Automattic/mongoose#6028
  • Loading branch information
vkarpov15 authored and daprahamian committed Feb 14, 2018
1 parent 7ac171e commit 2d3fa98
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
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();
});
}
});
});

0 comments on commit 2d3fa98

Please sign in to comment.