Skip to content

Commit

Permalink
fix(transactions): fix error message for attempting sharded
Browse files Browse the repository at this point in the history
transactions below 4.2

The original error would throw for all sharded deployments.
This fixes the wire check and makes sure it only throws
for wire checks below wire version 8
  • Loading branch information
daprahamian committed Aug 13, 2019
1 parent eb5cc6b commit eb5dfc9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/core/sessions.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ class ClientSession extends EventEmitter {
const topologyMaxWireVersion = maxWireVersion(this.topology);
if (
isSharded(this.topology) &&
(topologyMaxWireVersion == null ||
topologyMaxWireVersion < minWireVersionForShardedTransactions)
topologyMaxWireVersion != null &&
topologyMaxWireVersion < minWireVersionForShardedTransactions
) {
throw new MongoError('Transactions are not supported on sharded clusters in MongoDB < 4.2.');
}
Expand Down
7 changes: 7 additions & 0 deletions lib/core/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ function maxWireVersion(topologyOrServer) {
return topologyOrServer.ismaster.maxWireVersion;
}

if (typeof topologyOrServer.lastIsMaster === 'function') {
const lastIsMaster = topologyOrServer.lastIsMaster();
if (lastIsMaster) {
return lastIsMaster.maxWireVersion;
}
}

if (topologyOrServer.description) {
return topologyOrServer.description.maxWireVersion;
}
Expand Down

0 comments on commit eb5dfc9

Please sign in to comment.