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

Commit 2d3fa98

Browse files
vkarpov15daprahamian
authored andcommitted
fix(connection): make pool not try to reconnect forever when reconnectTries = 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
1 parent 7ac171e commit 2d3fa98

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

lib/connection/pool.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ function attemptReconnect(self) {
364364
// Count down the number of reconnects
365365
self.retriesLeft = self.retriesLeft - 1;
366366
// How many retries are left
367-
if (self.retriesLeft === 0) {
367+
if (self.retriesLeft <= 0) {
368368
// Destroy the instance
369369
self.destroy();
370370
// Emit close event

test/tests/functional/server_tests.js

+23
Original file line numberDiff line numberDiff line change
@@ -1077,4 +1077,27 @@ describe('Server tests', function() {
10771077
}
10781078
});
10791079
});
1080+
1081+
it('Should not try to reconnect forever if reconnectTries = 0', {
1082+
metadata: { requires: { topology: 'single' } },
1083+
1084+
test: function(done) {
1085+
// Attempt to connect
1086+
let server = new Server({
1087+
host: 'doesntexist',
1088+
bson: new Bson(),
1089+
reconnectTries: 0
1090+
});
1091+
1092+
// Add event listeners
1093+
server.on('error', function() {});
1094+
1095+
// Start connection
1096+
server.connect();
1097+
1098+
server.s.pool.on('reconnectFailed', function() {
1099+
done();
1100+
});
1101+
}
1102+
});
10801103
});

0 commit comments

Comments
 (0)