From 494dffb915c30809fd077ce9bd53a24f01986e5c Mon Sep 17 00:00:00 2001 From: Matt Broadstone Date: Mon, 24 Feb 2020 12:28:48 -0500 Subject: [PATCH] fix(topology): enter `STATE_CLOSING` before draining waitQueue NODE-2468 --- lib/core/sdam/topology.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/core/sdam/topology.js b/lib/core/sdam/topology.js index 57c53b2c32f..ed1df2d3f00 100644 --- a/lib/core/sdam/topology.js +++ b/lib/core/sdam/topology.js @@ -312,7 +312,7 @@ class Topology extends EventEmitter { } options = options || {}; - if (this.s.state === STATE_CLOSED) { + if (this.s.state === STATE_CLOSED || this.s.state === STATE_CLOSING) { if (typeof callback === 'function') { callback(); } @@ -320,6 +320,8 @@ class Topology extends EventEmitter { return; } + stateTransition(this, STATE_CLOSING); + drainWaitQueue(this[kWaitQueue], new MongoError('Topology closed')); drainTimerQueue(this.s.connectionTimers); @@ -336,8 +338,6 @@ class Topology extends EventEmitter { delete this.s.detectTopologyDescriptionChange; } - stateTransition(this, STATE_CLOSING); - this.s.sessions.forEach(session => session.endSession()); this.s.sessionPool.endAllPooledSessions(() => { eachAsync(