From 329c5767a505ee29e0c9615bb53a4114d59853ef Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Wed, 12 May 2021 15:35:38 -0400 Subject: [PATCH 1/2] fix: check clusterTime is defined before access --- lib/core/wireprotocol/command.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/core/wireprotocol/command.js b/lib/core/wireprotocol/command.js index fd581c84f4..378fe3e93c 100644 --- a/lib/core/wireprotocol/command.js +++ b/lib/core/wireprotocol/command.js @@ -45,14 +45,20 @@ function _command(server, ns, cmd, options, callback) { const shouldUseOpMsg = supportsOpMsg(server); const session = options.session; - let clusterTime = server.clusterTime; + const serverClusterTime = server.clusterTime; + let clusterTime = serverClusterTime; let finalCmd = Object.assign({}, cmd); if (hasSessionSupport(server) && session) { + const sessionClusterTime = session.clusterTime; if ( - session.clusterTime && - session.clusterTime.clusterTime.greaterThan(clusterTime.clusterTime) + serverClusterTime && + serverClusterTime.clusterTime && + sessionClusterTime && + sessionClusterTime.clusterTime ) { - clusterTime = session.clusterTime; + if (sessionClusterTime.clusterTime.greaterThan(serverClusterTime.clusterTime)) { + clusterTime = sessionClusterTime; + } } const err = applySession(session, finalCmd, options); @@ -61,8 +67,8 @@ function _command(server, ns, cmd, options, callback) { } } - // if we have a known cluster time, gossip it if (clusterTime) { + // if we have a known cluster time, gossip it finalCmd.$clusterTime = clusterTime; } From 92f424996a544ddce4e50d2ea5216e1ff0e1cec4 Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Mon, 17 May 2021 15:20:51 -0400 Subject: [PATCH 2/2] fix: collapse if stmt --- lib/core/wireprotocol/command.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/core/wireprotocol/command.js b/lib/core/wireprotocol/command.js index 378fe3e93c..9e687f8c95 100644 --- a/lib/core/wireprotocol/command.js +++ b/lib/core/wireprotocol/command.js @@ -54,11 +54,10 @@ function _command(server, ns, cmd, options, callback) { serverClusterTime && serverClusterTime.clusterTime && sessionClusterTime && - sessionClusterTime.clusterTime + sessionClusterTime.clusterTime && + sessionClusterTime.clusterTime.greaterThan(serverClusterTime.clusterTime) ) { - if (sessionClusterTime.clusterTime.greaterThan(serverClusterTime.clusterTime)) { - clusterTime = sessionClusterTime; - } + clusterTime = sessionClusterTime; } const err = applySession(session, finalCmd, options);