Skip to content

Commit

Permalink
refactor: don't store errors directly on TopologyDescription
Browse files Browse the repository at this point in the history
Propagating and storing an error on the `TopologyDescription` has
the unintended side-effect of never removing said error, thus
effectively poisoning the description in the event of failure
recovery.
  • Loading branch information
mbroadst committed Dec 30, 2019
1 parent abe0ff9 commit 8c89b89
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions lib/core/sdam/topology_description.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ class TopologyDescription {
maxSetVersion,
maxElectionId,
commonWireVersion,
options,
error
options
) {
options = options || {};

Expand All @@ -47,7 +46,6 @@ class TopologyDescription {
this.logicalSessionTimeoutMinutes = null;
this.heartbeatFrequencyMS = options.heartbeatFrequencyMS || 0;
this.localThresholdMS = options.localThresholdMS || 0;
this.error = error;
this.commonWireVersion = commonWireVersion || null;

// save this locally, but don't display when printing the instance out
Expand Down Expand Up @@ -133,7 +131,6 @@ class TopologyDescription {
let maxSetVersion = this.maxSetVersion;
let maxElectionId = this.maxElectionId;
let commonWireVersion = this.commonWireVersion;
let error = serverDescription.error || this.error;

const serverType = serverDescription.type;
let serverDescriptions = new Map(this.servers);
Expand All @@ -159,8 +156,7 @@ class TopologyDescription {
maxSetVersion,
maxElectionId,
commonWireVersion,
this.options,
error
this.options
);
}

Expand Down Expand Up @@ -241,11 +237,17 @@ class TopologyDescription {
maxSetVersion,
maxElectionId,
commonWireVersion,
this.options,
error
this.options
);
}

get error() {
const descriptionsWithError = Array.from(this.servers.values()).filter(sd => sd.error);
if (descriptionsWithError.length > 0) {
return descriptionsWithError[0].error;
}
}

/**
* Determines if the topology description has any known servers
*/
Expand Down

0 comments on commit 8c89b89

Please sign in to comment.