Skip to content

Commit 62ada2a

Browse files
committed
fix(server): don't emit error in connect if closing/closed
1 parent a471707 commit 62ada2a

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

lib/core/sdam/server.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ class Server extends EventEmitter {
166166
relayEvents(this.s.pool, this, ['commandStarted', 'commandSucceeded', 'commandFailed']);
167167

168168
stateTransition(this, STATE_CONNECTING);
169+
169170
this.s.pool.connect(connectEventHandler(this));
170171
}
171172

@@ -465,10 +466,14 @@ function executeWriteOperation(args, options, callback) {
465466

466467
function connectEventHandler(server) {
467468
return function(err, conn) {
469+
if (server.s.state === STATE_CLOSING || server.s.state === STATE_CLOSED) {
470+
return;
471+
}
472+
468473
if (err) {
469474
server.emit('error', new MongoNetworkError(err));
470475

471-
stateTransition(this, STATE_CLOSED);
476+
stateTransition(server, STATE_CLOSED);
472477
server.emit('close');
473478
return;
474479
}

0 commit comments

Comments
 (0)