From eb5dfc945e3a673d8c40c3f4ee0c2c2b0db3695d Mon Sep 17 00:00:00 2001 From: Dan Aprahamian Date: Thu, 1 Aug 2019 16:03:34 -0400 Subject: [PATCH] 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 --- lib/core/sessions.js | 4 ++-- lib/core/utils.js | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/core/sessions.js b/lib/core/sessions.js index 66a0580c2b..e9016347cc 100644 --- a/lib/core/sessions.js +++ b/lib/core/sessions.js @@ -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.'); } diff --git a/lib/core/utils.js b/lib/core/utils.js index eac0ee4ab0..47cb7df8b0 100644 --- a/lib/core/utils.js +++ b/lib/core/utils.js @@ -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; }