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

Commit

Permalink
fix(SDAM): emit SDAM events on close and reconnect
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
durran authored and mbroadst committed Jul 27, 2017
1 parent 44d0941 commit 3451ff0
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/topologies/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,13 @@ var eventHandler = function(self, event) {
delete servers[self.id];
}

if (event === 'close') {
// Closing emits a server description changed event going to unknown.
sdam.emitServerDescriptionChanged(self, {
address: self.name, arbiters: [], hosts: [], passives: [], type: 'Unknown'
});
}

// Reconnect failed return error
if(event == 'reconnectFailed') {
self.emit('reconnectFailed', err);
Expand All @@ -331,6 +338,11 @@ var eventHandler = function(self, event) {

// Reconnect event, emit the server
if(event == 'reconnect') {
// Reconnecting emits a server description changed event going from unknown to the
// current server type.
sdam.emitServerDescriptionChanged(self, {
address: self.name, arbiters: [], hosts: [], passives: [], type: sdam.getTopologyType(self)
});
return self.emit(event, self);
}

Expand Down

0 comments on commit 3451ff0

Please sign in to comment.