Skip to content

Commit 8c89b89

Browse files
committed
refactor: don't store errors directly on TopologyDescription
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.
1 parent abe0ff9 commit 8c89b89

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

lib/core/sdam/topology_description.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ class TopologyDescription {
2828
maxSetVersion,
2929
maxElectionId,
3030
commonWireVersion,
31-
options,
32-
error
31+
options
3332
) {
3433
options = options || {};
3534

@@ -47,7 +46,6 @@ class TopologyDescription {
4746
this.logicalSessionTimeoutMinutes = null;
4847
this.heartbeatFrequencyMS = options.heartbeatFrequencyMS || 0;
4948
this.localThresholdMS = options.localThresholdMS || 0;
50-
this.error = error;
5149
this.commonWireVersion = commonWireVersion || null;
5250

5351
// save this locally, but don't display when printing the instance out
@@ -133,7 +131,6 @@ class TopologyDescription {
133131
let maxSetVersion = this.maxSetVersion;
134132
let maxElectionId = this.maxElectionId;
135133
let commonWireVersion = this.commonWireVersion;
136-
let error = serverDescription.error || this.error;
137134

138135
const serverType = serverDescription.type;
139136
let serverDescriptions = new Map(this.servers);
@@ -159,8 +156,7 @@ class TopologyDescription {
159156
maxSetVersion,
160157
maxElectionId,
161158
commonWireVersion,
162-
this.options,
163-
error
159+
this.options
164160
);
165161
}
166162

@@ -241,11 +237,17 @@ class TopologyDescription {
241237
maxSetVersion,
242238
maxElectionId,
243239
commonWireVersion,
244-
this.options,
245-
error
240+
this.options
246241
);
247242
}
248243

244+
get error() {
245+
const descriptionsWithError = Array.from(this.servers.values()).filter(sd => sd.error);
246+
if (descriptionsWithError.length > 0) {
247+
return descriptionsWithError[0].error;
248+
}
249+
}
250+
249251
/**
250252
* Determines if the topology description has any known servers
251253
*/

0 commit comments

Comments
 (0)