From 0fd4d38edb1fe19d8c2c1aa2c3f1c966d9750a7f Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Sat, 3 Feb 2018 19:38:49 -0800 Subject: [PATCH 1/2] fix(connection): make pool not try to reconnect forever when reconnectTries = 0 --- lib/connection/pool.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From b29aca29f5075af7dab7827365cc4f0f48647e1f Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Fri, 9 Feb 2018 17:13:10 -0800 Subject: [PATCH 2/2] test(server): add test coverage for #275 Re: Automattic/mongoose#6028 --- test/tests/functional/server_tests.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) 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(); + }); + } + }); });