Skip to content
This repository was archived by the owner on Feb 4, 2022. It is now read-only.

Commit 3451ff0

Browse files
durranmbroadst
authored andcommitted
fix(SDAM): emit SDAM events on close and reconnect
* Emit SDAM events on close and reconnect: According to the SDAM specification, when a server isMaster fails either due to a network issue, the server is not available, or ok !== 1 then the server type must change to Unknown. This must then emit a serverDescriptionChanged event since the type has changed. This pull emits that event now when the server is closed to set it as Unknown, and when the server reconnects to set it back to the proper type. This was previously happening on single server types. * Fix typo in comment
1 parent 44d0941 commit 3451ff0

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

lib/topologies/server.js

+12
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,13 @@ var eventHandler = function(self, event) {
312312
delete servers[self.id];
313313
}
314314

315+
if (event === 'close') {
316+
// Closing emits a server description changed event going to unknown.
317+
sdam.emitServerDescriptionChanged(self, {
318+
address: self.name, arbiters: [], hosts: [], passives: [], type: 'Unknown'
319+
});
320+
}
321+
315322
// Reconnect failed return error
316323
if(event == 'reconnectFailed') {
317324
self.emit('reconnectFailed', err);
@@ -331,6 +338,11 @@ var eventHandler = function(self, event) {
331338

332339
// Reconnect event, emit the server
333340
if(event == 'reconnect') {
341+
// Reconnecting emits a server description changed event going from unknown to the
342+
// current server type.
343+
sdam.emitServerDescriptionChanged(self, {
344+
address: self.name, arbiters: [], hosts: [], passives: [], type: sdam.getTopologyType(self)
345+
});
334346
return self.emit(event, self);
335347
}
336348

0 commit comments

Comments
 (0)