Skip to content

Commit 494dffb

Browse files
committed
fix(topology): enter STATE_CLOSING before draining waitQueue
NODE-2468
1 parent bf701d6 commit 494dffb

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

lib/core/sdam/topology.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -312,14 +312,16 @@ class Topology extends EventEmitter {
312312
}
313313

314314
options = options || {};
315-
if (this.s.state === STATE_CLOSED) {
315+
if (this.s.state === STATE_CLOSED || this.s.state === STATE_CLOSING) {
316316
if (typeof callback === 'function') {
317317
callback();
318318
}
319319

320320
return;
321321
}
322322

323+
stateTransition(this, STATE_CLOSING);
324+
323325
drainWaitQueue(this[kWaitQueue], new MongoError('Topology closed'));
324326
drainTimerQueue(this.s.connectionTimers);
325327

@@ -336,8 +338,6 @@ class Topology extends EventEmitter {
336338
delete this.s.detectTopologyDescriptionChange;
337339
}
338340

339-
stateTransition(this, STATE_CLOSING);
340-
341341
this.s.sessions.forEach(session => session.endSession());
342342
this.s.sessionPool.endAllPooledSessions(() => {
343343
eachAsync(

0 commit comments

Comments
 (0)