Skip to content

Commit

Permalink
fix(pool): don't reset a pool if we'not already connected
Browse files Browse the repository at this point in the history
  • Loading branch information
mbroadst committed Nov 5, 2019
1 parent ec1e04c commit 32316e4
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/core/connection/pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -739,6 +747,9 @@ Pool.prototype.reset = function(callback) {
}

resetPoolState(this);

// attempt reexecution
process.nextTick(() => _execute(this)());
if (typeof callback === 'function') {
callback(null, null);
}
Expand Down

0 comments on commit 32316e4

Please sign in to comment.