From 2eab8aa63f15a425a2901b7f4c59b0744e78db88 Mon Sep 17 00:00:00 2001 From: Matt Broadstone Date: Thu, 25 Jul 2019 15:45:43 -0400 Subject: [PATCH] fix(replset): correct legacy max staleness calculation We were calculating lastUpdateTime using nanoseconds instead of milliseconds, despite calculating maxStaleness with a millisecond lastWriteDate --- lib/core/topologies/replset.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/core/topologies/replset.js b/lib/core/topologies/replset.js index 3e1520ab50..690cf2615b 100644 --- a/lib/core/topologies/replset.js +++ b/lib/core/topologies/replset.js @@ -415,10 +415,10 @@ var pingServer = function(self, server, cb) { // Calculate latency var latencyMS = new Date().getTime() - start; + // Set the last updatedTime - var hrTime = process.hrtime(); - // Calculate the last update time - server.lastUpdateTime = hrTime[0] * 1000 + Math.round(hrTime[1] / 1000); + var hrtime = process.hrtime(); + server.lastUpdateTime = (hrtime[0] * 1e9 + hrtime[1]) / 1e6; // We had an error, remove it from the state if (err) {