Skip to content

Commit

Permalink
refactor: ensure selected server in retry supports retryable reads
Browse files Browse the repository at this point in the history
  • Loading branch information
mbroadst authored and daprahamian committed Aug 13, 2019
1 parent 360975a commit 3913eaa
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/operations/execute_operation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}
Expand All @@ -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);
Expand Down

0 comments on commit 3913eaa

Please sign in to comment.