Skip to content

Commit

Permalink
fix(NODE-3192): check clusterTime is defined before access (#2806)
Browse files Browse the repository at this point in the history
  • Loading branch information
nbbeeken authored May 18, 2021
1 parent 1967515 commit 6ceace6
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/core/wireprotocol/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,19 @@ 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 &&
sessionClusterTime.clusterTime.greaterThan(serverClusterTime.clusterTime)
) {
clusterTime = session.clusterTime;
clusterTime = sessionClusterTime;
}

const err = applySession(session, finalCmd, options);
Expand All @@ -61,8 +66,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;
}

Expand Down

0 comments on commit 6ceace6

Please sign in to comment.