Skip to content

Commit

Permalink
fix(server): don't emit error in connect if closing/closed
Browse files Browse the repository at this point in the history
  • Loading branch information
mbroadst committed Nov 5, 2019
1 parent a471707 commit 62ada2a
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/core/sdam/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ class Server extends EventEmitter {
relayEvents(this.s.pool, this, ['commandStarted', 'commandSucceeded', 'commandFailed']);

stateTransition(this, STATE_CONNECTING);

this.s.pool.connect(connectEventHandler(this));
}

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

function connectEventHandler(server) {
return function(err, conn) {
if (server.s.state === STATE_CLOSING || server.s.state === STATE_CLOSED) {
return;
}

if (err) {
server.emit('error', new MongoNetworkError(err));

stateTransition(this, STATE_CLOSED);
stateTransition(server, STATE_CLOSED);
server.emit('close');
return;
}
Expand Down

0 comments on commit 62ada2a

Please sign in to comment.