diff --git a/lib/connection/pool.js b/lib/connection/pool.js index 3fdd8076d..c0613e2fd 100644 --- a/lib/connection/pool.js +++ b/lib/connection/pool.js @@ -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 diff --git a/test/tests/functional/server_tests.js b/test/tests/functional/server_tests.js index ce95ab618..c62674ca7 100644 --- a/test/tests/functional/server_tests.js +++ b/test/tests/functional/server_tests.js @@ -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(); + }); + } + }); });