From 0198b9b5935d819d653aec9b15cb06de4b33392d Mon Sep 17 00:00:00 2001 From: uzlopak Date: Tue, 14 Jun 2022 16:10:29 +0200 Subject: [PATCH] remove connect-option reconnectTries and reconnectInterval --- docs/connections.md | 1 - lib/connection.js | 7 +++---- lib/error/disconnected.js | 7 +++---- lib/index.js | 4 ---- 4 files changed, 6 insertions(+), 13 deletions(-) diff --git a/docs/connections.md b/docs/connections.md index 0133235c893..ffee57fc4cb 100644 --- a/docs/connections.md +++ b/docs/connections.md @@ -243,7 +243,6 @@ connection may emit. * `error`: Emitted if an error occurs on a connection, like a `parseError` due to malformed data or a payload larger than [16MB](https://docs.mongodb.com/manual/reference/limits/#BSON-Document-Size). * `fullsetup`: Emitted when you're connecting to a replica set and Mongoose has successfully connected to the primary and at least one secondary. * `all`: Emitted when you're connecting to a replica set and Mongoose has successfully connected to all servers specified in your connection string. -* `reconnectFailed`: Emitted when you're connected to a standalone server and Mongoose has run out of [`reconnectTries`](https://thecodebarbarian.com/managing-connections-with-the-mongodb-node-driver.html#handling-single-server-outages). The [MongoDB driver](http://npmjs.com/package/mongodb) will no longer attempt to reconnect after this event is emitted. This event will never be emitted if you're connected to a replica set. When you're connecting to a single MongoDB server (a "standalone"), Mongoose will emit 'disconnected' if it gets disconnected from the standalone server, and 'connected' if it successfully connects to the standalone. In a diff --git a/lib/connection.js b/lib/connection.js index 54d98cec28e..b82a93167be 100644 --- a/lib/connection.js +++ b/lib/connection.js @@ -9,6 +9,7 @@ const EventEmitter = require('events').EventEmitter; const Schema = require('./schema'); const STATES = require('./connectionstate'); const MongooseError = require('./error/index'); +const DisconnectedError = require('./error/disconnected'); const SyncIndexesError = require('./error/syncIndexes'); const PromiseProvider = require('./promise_provider'); const ServerSelectionError = require('./error/serverSelection'); @@ -565,8 +566,7 @@ function _wrapConnHelper(fn) { const argsWithoutCb = typeof cb === 'function' ? Array.prototype.slice.call(arguments, 0, arguments.length - 1) : Array.prototype.slice.call(arguments); - const disconnectedError = new MongooseError('Connection ' + this.id + - ' was disconnected when calling `' + fn.name + '`'); + const disconnectedError = new DisconnectedError(this.id, fn.name); return promiseOrCallback(cb, cb => { immediate(() => { @@ -1260,8 +1260,7 @@ Connection.prototype.deleteModel = function(name) { */ Connection.prototype.watch = function(pipeline, options) { - const disconnectedError = new MongooseError('Connection ' + this.id + - ' was disconnected when calling `watch()`'); + const disconnectedError = new DisconnectedError(this.id, 'watch'); const changeStreamThunk = cb => { immediate(() => { diff --git a/lib/error/disconnected.js b/lib/error/disconnected.js index 777a1def270..9e8c6125c14 100644 --- a/lib/error/disconnected.js +++ b/lib/error/disconnected.js @@ -16,10 +16,9 @@ class DisconnectedError extends MongooseError { /** * @param {String} connectionString */ - constructor(connectionString) { - super('Ran out of retries trying to reconnect to "' + - connectionString + '". Try setting `server.reconnectTries` and ' + - '`server.reconnectInterval` to something higher.'); + constructor(id, fnName) { + super('Connection ' + id + + ' was disconnected when calling `' + fnName + '()`'); } } diff --git a/lib/index.js b/lib/index.js index a734bc6949c..c26ec992a3f 100644 --- a/lib/index.js +++ b/lib/index.js @@ -260,8 +260,6 @@ Mongoose.prototype.get = Mongoose.prototype.set; * @param {String} [options.user] username for authentication, equivalent to `options.auth.user`. Maintained for backwards compatibility. * @param {String} [options.pass] password for authentication, equivalent to `options.auth.password`. Maintained for backwards compatibility. * @param {Boolean} [options.autoIndex=true] Mongoose-specific option. Set to false to disable automatic index creation for all models associated with this connection. - * @param {Number} [options.reconnectTries=30] If you're connected to a single server or mongos proxy (as opposed to a replica set), the MongoDB driver will try to reconnect every `reconnectInterval` milliseconds for `reconnectTries` times, and give up afterward. When the driver gives up, the mongoose connection emits a `reconnectFailed` event. This option does nothing for replica set connections. - * @param {Number} [options.reconnectInterval=1000] See `reconnectTries` option above. * @param {Class} [options.promiseLibrary] Sets the [underlying driver's promise library](https://mongodb.github.io/node-mongodb-native/3.1/api/MongoClient.html). * @param {Number} [options.maxPoolSize=5] The maximum number of sockets the MongoDB driver will keep open for this connection. Keep in mind that MongoDB only allows one operation per socket at a time, so you may want to increase this if you find you have a few slow queries that are blocking faster queries from proceeding. See [Slow Trains in MongoDB and Node.js](https://thecodebarbarian.com/slow-trains-in-mongodb-and-nodejs). * @param {Number} [options.minPoolSize=1] The minimum number of sockets the MongoDB driver will keep open for this connection. Keep in mind that MongoDB only allows one operation per socket at a time, so you may want to increase this if you find you have a few slow queries that are blocking faster queries from proceeding. See [Slow Trains in MongoDB and Node.js](https://thecodebarbarian.com/slow-trains-in-mongodb-and-nodejs). @@ -323,8 +321,6 @@ Mongoose.prototype.createConnection = function(uri, options, callback) { * @param {Number} [options.serverSelectionTimeoutMS] If `useUnifiedTopology = true`, the MongoDB driver will try to find a server to send any given operation to, and keep retrying for `serverSelectionTimeoutMS` milliseconds before erroring out. If not set, the MongoDB driver defaults to using `30000` (30 seconds). * @param {Number} [options.heartbeatFrequencyMS] If `useUnifiedTopology = true`, the MongoDB driver sends a heartbeat every `heartbeatFrequencyMS` to check on the status of the connection. A heartbeat is subject to `serverSelectionTimeoutMS`, so the MongoDB driver will retry failed heartbeats for up to 30 seconds by default. Mongoose only emits a `'disconnected'` event after a heartbeat has failed, so you may want to decrease this setting to reduce the time between when your server goes down and when Mongoose emits `'disconnected'`. We recommend you do **not** set this setting below 1000, too many heartbeats can lead to performance degradation. * @param {Boolean} [options.autoIndex=true] Mongoose-specific option. Set to false to disable automatic index creation for all models associated with this connection. - * @param {Number} [options.reconnectTries=30] If you're connected to a single server or mongos proxy (as opposed to a replica set), the MongoDB driver will try to reconnect every `reconnectInterval` milliseconds for `reconnectTries` times, and give up afterward. When the driver gives up, the mongoose connection emits a `reconnectFailed` event. This option does nothing for replica set connections. - * @param {Number} [options.reconnectInterval=1000] See `reconnectTries` option above. * @param {Class} [options.promiseLibrary] Sets the [underlying driver's promise library](https://mongodb.github.io/node-mongodb-native/3.1/api/MongoClient.html). * @param {Number} [options.connectTimeoutMS=30000] How long the MongoDB driver will wait before killing a socket due to inactivity _during initial connection_. Defaults to 30000. This option is passed transparently to [Node.js' `socket#setTimeout()` function](https://nodejs.org/api/net.html#net_socket_settimeout_timeout_callback). * @param {Number} [options.socketTimeoutMS=30000] How long the MongoDB driver will wait before killing a socket due to inactivity _after initial connection_. A socket may be inactive because of either no activity or a long-running operation. This is set to `30000` by default, you should set this to 2-3x your longest running operation if you expect some of your database operations to run longer than 20 seconds. This option is passed to [Node.js `socket#setTimeout()` function](https://nodejs.org/api/net.html#net_socket_settimeout_timeout_callback) after the MongoDB driver successfully completes.