From 32316e4c55044d175c230600d9c2669f90bb21c6 Mon Sep 17 00:00:00 2001 From: Matt Broadstone Date: Sun, 3 Nov 2019 08:56:42 -0500 Subject: [PATCH] fix(pool): don't reset a pool if we'not already connected --- lib/core/connection/pool.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/core/connection/pool.js b/lib/core/connection/pool.js index 318f5fbe42..e5bfdaae07 100644 --- a/lib/core/connection/pool.js +++ b/lib/core/connection/pool.js @@ -720,6 +720,14 @@ Pool.prototype.destroy = function(force, callback) { * @param {function} [callback] */ Pool.prototype.reset = function(callback) { + if (this.s.state !== CONNECTED) { + if (typeof callback === 'function') { + callback(new MongoError('pool is not connected, reset aborted')); + } + + return; + } + const connections = this.availableConnections.concat(this.inUseConnections); eachAsync( connections, @@ -739,6 +747,9 @@ Pool.prototype.reset = function(callback) { } resetPoolState(this); + + // attempt reexecution + process.nextTick(() => _execute(this)()); if (typeof callback === 'function') { callback(null, null); }