-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ChangeStream): whitelist resumable errors (#2337)
- Changes which errors are considered resumable on change streams, adding support for the new ResumableChangeStreamError label. - Updates ChangeStream prose tests which described startAfter behavior for unsupported server versions. - Fixes use of startAfter/resumeAfter when resuming from an invalidate event. Implement prose tests #17 and #18. NODE-2478
- Loading branch information
Showing
19 changed files
with
6,080 additions
and
744 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,38 @@ | ||
'use strict'; | ||
|
||
const MongoNetworkError = require('./core').MongoNetworkError; | ||
const mongoErrorContextSymbol = require('./core').mongoErrorContextSymbol; | ||
|
||
const GET_MORE_NON_RESUMABLE_CODES = new Set([ | ||
136, // CappedPositionLost | ||
237, // CursorKilled | ||
11601 // Interrupted | ||
// From spec@https://github.com/mongodb/specifications/blob/f93d78191f3db2898a59013a7ed5650352ef6da8/source/change-streams/change-streams.rst#resumable-error | ||
const GET_MORE_RESUMABLE_CODES = new Set([ | ||
6, // HostUnreachable | ||
7, // HostNotFound | ||
89, // NetworkTimeout | ||
91, // ShutdownInProgress | ||
189, // PrimarySteppedDown | ||
262, // ExceededTimeLimit | ||
9001, // SocketException | ||
10107, // NotMaster | ||
11600, // InterruptedAtShutdown | ||
11602, // InterruptedDueToReplStateChange | ||
13435, // NotMasterNoSlaveOk | ||
13436, // NotMasterOrSecondary | ||
63, // StaleShardVersion | ||
150, // StaleEpoch | ||
13388, // StaleConfig | ||
234, // RetryChangeStream | ||
133 // FailedToSatisfyReadPreference | ||
]); | ||
|
||
// From spec@https://github.com/mongodb/specifications/blob/7a2e93d85935ee4b1046a8d2ad3514c657dc74fa/source/change-streams/change-streams.rst#resumable-error: | ||
// | ||
// An error is considered resumable if it meets any of the following criteria: | ||
// - any error encountered which is not a server error (e.g. a timeout error or network error) | ||
// - any server error response from a getMore command excluding those containing the error label | ||
// NonRetryableChangeStreamError and those containing the following error codes: | ||
// - Interrupted: 11601 | ||
// - CappedPositionLost: 136 | ||
// - CursorKilled: 237 | ||
// | ||
// An error on an aggregate command is not a resumable error. Only errors on a getMore command may be considered resumable errors. | ||
|
||
function isGetMoreError(error) { | ||
if (error[mongoErrorContextSymbol]) { | ||
return error[mongoErrorContextSymbol].isGetMore; | ||
} | ||
} | ||
|
||
function isResumableError(error) { | ||
if (!isGetMoreError(error)) { | ||
return false; | ||
} | ||
|
||
function isResumableError(error, wireVersion) { | ||
if (error instanceof MongoNetworkError) { | ||
return true; | ||
} | ||
|
||
return !( | ||
GET_MORE_NON_RESUMABLE_CODES.has(error.code) || | ||
error.hasErrorLabel('NonRetryableChangeStreamError') | ||
); | ||
if (wireVersion >= 9) { | ||
return error.hasErrorLabel('ResumableChangeStreamError'); | ||
} | ||
|
||
return GET_MORE_RESUMABLE_CODES.has(error.code); | ||
} | ||
|
||
module.exports = { GET_MORE_NON_RESUMABLE_CODES, isResumableError }; | ||
module.exports = { GET_MORE_RESUMABLE_CODES, isResumableError }; |
Oops, something went wrong.