Skip to content

Commit a630389

Browse files
committed
refactor: wait until server destroyed before stopping event relay
Some monitoring events (such as connection pool closed, or a return of a connection to the pool) are desired _after_ a server has been closed/destroyed.
1 parent c04a520 commit a630389

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

lib/core/sdam/topology.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,7 @@ const SERVER_RELAY_EVENTS = [
5353
].concat(CMAP_EVENT_NAMES);
5454

5555
// all events we listen to from `Server` instances
56-
const LOCAL_SERVER_EVENTS = SERVER_RELAY_EVENTS.concat([
57-
'error',
58-
'connect',
59-
'descriptionReceived',
60-
'close',
61-
'ended'
62-
]);
56+
const LOCAL_SERVER_EVENTS = ['error', 'connect', 'descriptionReceived', 'close', 'ended'];
6357

6458
const STATE_CLOSING = common.STATE_CLOSING;
6559
const STATE_CLOSED = common.STATE_CLOSED;
@@ -780,6 +774,7 @@ function destroyServer(server, topology, options, callback) {
780774
new events.ServerClosedEvent(topology.s.id, server.description.address)
781775
);
782776

777+
SERVER_RELAY_EVENTS.forEach(event => server.removeAllListeners(event));
783778
if (typeof callback === 'function') {
784779
callback();
785780
}

0 commit comments

Comments
 (0)