From 3913eaa6e87d0be0b4d35b5fc44cad51cdd9e696 Mon Sep 17 00:00:00 2001 From: Matt Broadstone Date: Mon, 15 Jul 2019 10:06:08 -0400 Subject: [PATCH] refactor: ensure selected server in retry supports retryable reads --- lib/operations/execute_operation.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/operations/execute_operation.js b/lib/operations/execute_operation.js index 84a53a5967..6c574a6ceb 100644 --- a/lib/operations/execute_operation.js +++ b/lib/operations/execute_operation.js @@ -94,6 +94,10 @@ function executeOperation(topology, operation, callback) { }); } +function supportsRetryableReads(server) { + return maxWireVersion(server) >= 6; +} + function executeWithServerSelection(topology, operation, callback) { const readPreference = operation.readPreference || ReadPreference.primary; @@ -108,7 +112,7 @@ function executeWithServerSelection(topology, operation, callback) { // select a new server, and attempt to retry the operation topology.selectServer(readPreference, (err, server) => { - if (err) { + if (err || !supportsRetryableReads(server)) { callback(err, null); return; } @@ -127,7 +131,7 @@ function executeWithServerSelection(topology, operation, callback) { const shouldRetryReads = topology.s.options.retryReads !== false && (operation.session && !operation.session.inTransaction()) && - maxWireVersion(server) >= 6; + supportsRetryableReads(server); if (operation.hasAspect(Aspect.RETRYABLE) && shouldRetryReads) { operation.execute(server, callbackWithRetry);