From 3ee0cd73e15ded98aef8eda21fc891bd14a8afd6 Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Sat, 8 Oct 2016 14:34:27 -0400 Subject: [PATCH] Set mongoOptions.server.reconnectTries = Infinity. Setting mongoOptions.server.auto_reconnect was removed by #7880 via commit 0ffb9ac8247c53b9ab5658d75139b64771fd4de3, though it seems the Server options still respect autoReconnect, even in version 2.2 of the driver: http://mongodb.github.io/node-mongodb-native/2.2/api/Server.html That said, having inspected the code of the `mongodb` package, I do not believe this change is really critical, since the default value for autoReconnect appears to be true. More importantly, I can't find any support in the code of the `mongodb` npm package or its dependencies for the claim that setting mongoOptions.server.reconnectTries to 0 is the same as making it infinite, so this commit sets it to Infinity. --- packages/mongo/mongo_driver.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/packages/mongo/mongo_driver.js b/packages/mongo/mongo_driver.js index 5d5ecbdcb8..77eabdc3b6 100644 --- a/packages/mongo/mongo_driver.js +++ b/packages/mongo/mongo_driver.js @@ -131,14 +131,17 @@ MongoConnection = function (url, options) { self._onFailoverHook = new Hook; var mongoOptions = _.extend({ - db: { safe: true }, - // Set reconnectTries to 0 which means keep trying to reconnect forever, - // rather than the default of losing the connection permanently after 30 - // retries (separated by 1000ms). - server: { reconnectTries: 0 }, - replSet: {} + db: { safe: true }, + // http://mongodb.github.io/node-mongodb-native/2.2/api/Server.html + server: { + // Reconnect on error. + autoReconnect: true, + // Try to reconnect forever, instead of stopping after 30 tries (the + // default), with each attempt separated by 1000ms. + reconnectTries: Infinity }, - Mongo._connectionOptions); + replSet: {} + }, Mongo._connectionOptions); // Disable the native parser by default, unless specifically enabled // in the mongo URL.