From 8c89b891bd1db7570547edffa7e30e092577d130 Mon Sep 17 00:00:00 2001 From: Matt Broadstone Date: Wed, 18 Dec 2019 10:50:41 -0500 Subject: [PATCH] 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. --- lib/core/sdam/topology_description.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/core/sdam/topology_description.js b/lib/core/sdam/topology_description.js index 51b4ecde9a..ba6a2507ee 100644 --- a/lib/core/sdam/topology_description.js +++ b/lib/core/sdam/topology_description.js @@ -28,8 +28,7 @@ class TopologyDescription { maxSetVersion, maxElectionId, commonWireVersion, - options, - error + options ) { options = options || {}; @@ -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 @@ -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); @@ -159,8 +156,7 @@ class TopologyDescription { maxSetVersion, maxElectionId, commonWireVersion, - this.options, - error + this.options ); } @@ -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 */