Skip to content

Commit

Permalink
refactor: make isSDAMUnrecoverableError more readable
Browse files Browse the repository at this point in the history
  • Loading branch information
mbroadst committed Aug 22, 2019
1 parent cf598e1 commit 4ec04f0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
18 changes: 13 additions & 5 deletions lib/core/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,19 @@ function isNodeShuttingDownError(err) {
* @param {Server} server
*/
function isSDAMUnrecoverableError(error, server) {
return (
error instanceof MongoParseError ||
((isRecoveringError(error) || isNotMasterError(error)) &&
(maxWireVersion(server) >= 8 && isNodeShuttingDownError(error)))
);
if (error instanceof MongoParseError) {
return true;
}

if (isRecoveringError(error) || isNotMasterError(error)) {
if (maxWireVersion(server) >= 8 && !isNodeShuttingDownError(error)) {
return false;
}

return true;
}

return false;
}

module.exports = {
Expand Down
4 changes: 3 additions & 1 deletion test/functional/connections_stepdown_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ describe('Connections survive primary step down', function() {
db.executeDbAdminCommand({ configureFailPoint: 'failCommand', mode: 'off' })
);

collection.insertOne({ test: 1 }).catch(err => expect(err.code).to.equal(10107));
return collection.insertOne({ test: 1 }).catch(err => expect(err.code).to.equal(10107));
})
.then(() => connectionCount(db).then(expectPoolWasCleared(initialConnectionCount)));
});
Expand All @@ -151,6 +151,7 @@ describe('Connections survive primary step down', function() {
deferred.push(() =>
db.executeDbAdminCommand({ configureFailPoint: 'failCommand', mode: 'off' })
);

return collection.insertOne({ test: 1 }).catch(err => expect(err.code).to.equal(91));
})
.then(() => connectionCount(db).then(expectPoolWasCleared(initialConnectionCount)));
Expand All @@ -172,6 +173,7 @@ describe('Connections survive primary step down', function() {
deferred.push(() =>
db.executeDbAdminCommand({ configureFailPoint: 'failCommand', mode: 'off' })
);

return collection.insertOne({ test: 1 }).catch(err => expect(err.code).to.equal(11600));
})
.then(() => connectionCount(db).then(expectPoolWasCleared(initialConnectionCount)));
Expand Down

0 comments on commit 4ec04f0

Please sign in to comment.