Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(NODE-3192): check clusterTime is defined before access #2806

Merged
merged 2 commits into from
May 18, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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