Skip to content

Commit eb5dfc9

Browse files
committed
fix(transactions): fix error message for attempting sharded
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
1 parent eb5cc6b commit eb5dfc9

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

lib/core/sessions.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,8 @@ class ClientSession extends EventEmitter {
192192
const topologyMaxWireVersion = maxWireVersion(this.topology);
193193
if (
194194
isSharded(this.topology) &&
195-
(topologyMaxWireVersion == null ||
196-
topologyMaxWireVersion < minWireVersionForShardedTransactions)
195+
topologyMaxWireVersion != null &&
196+
topologyMaxWireVersion < minWireVersionForShardedTransactions
197197
) {
198198
throw new MongoError('Transactions are not supported on sharded clusters in MongoDB < 4.2.');
199199
}

lib/core/utils.js

+7
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,13 @@ function maxWireVersion(topologyOrServer) {
8787
return topologyOrServer.ismaster.maxWireVersion;
8888
}
8989

90+
if (typeof topologyOrServer.lastIsMaster === 'function') {
91+
const lastIsMaster = topologyOrServer.lastIsMaster();
92+
if (lastIsMaster) {
93+
return lastIsMaster.maxWireVersion;
94+
}
95+
}
96+
9097
if (topologyOrServer.description) {
9198
return topologyOrServer.description.maxWireVersion;
9299
}

0 commit comments

Comments
 (0)