From eb5cc6b0e386f6d0ce20f81612e3a0f8e4d4fe0d Mon Sep 17 00:00:00 2001 From: Dan Aprahamian Date: Thu, 1 Aug 2019 16:02:32 -0400 Subject: [PATCH] fix(serverSelection): make sure to pass session to serverSelection The executeWithSelection changes failed to pass the session to server selection, which broke mongos pinning. This ensures that we pass a session to serverSelection. --- lib/operations/execute_operation.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/operations/execute_operation.js b/lib/operations/execute_operation.js index bef633758b..b6276f3ddb 100644 --- a/lib/operations/execute_operation.js +++ b/lib/operations/execute_operation.js @@ -132,6 +132,11 @@ function executeWithServerSelection(topology, operation, callback) { return; } + const serverSelectionOptions = { + readPreference, + session: operation.session + }; + function callbackWithRetry(err, result) { if (err == null) { return callback(null, result); @@ -142,7 +147,7 @@ function executeWithServerSelection(topology, operation, callback) { } // select a new server, and attempt to retry the operation - topology.selectServer(readPreference, (err, server) => { + topology.selectServer(serverSelectionOptions, (err, server) => { if (err || !supportsRetryableReads(server)) { callback(err, null); return; @@ -153,7 +158,7 @@ function executeWithServerSelection(topology, operation, callback) { } // select a server, and execute the operation against it - topology.selectServer(readPreference, (err, server) => { + topology.selectServer(serverSelectionOptions, (err, server) => { if (err) { callback(err, null); return;