@@ -296,12 +296,50 @@ ChangeStream.prototype.stream = function(options) {
296
296
return this . cursor . stream ( options ) ;
297
297
} ;
298
298
299
+ const RESUMABLE_ERROR_CODES = new Set ( [
300
+ 6 , // HostUnreachable
301
+ 7 , // HostNotFound
302
+ 50 , // ExceededTimeLimit
303
+ 89 , // NetworkTimeout
304
+ 189 , // PrimarySteppedDown
305
+ 216 , // ElectionInProgress
306
+ 234 , // RetryChangeStream
307
+ 9001 , // SocketException
308
+ 10107 , // NotMaster
309
+ 11602 , // InterruptedDueToReplStateChange
310
+ 13435 , // NotMasterNoSlaveOk
311
+ 13436 // NotMasterOrSecondary
312
+ ] ) ;
313
+
314
+ // TODO: will be used for check for getMore errors
315
+ // const GET_MORE_NON_RESUMABLE_CODES = new Set([
316
+ // 136, // CappedPositionLost
317
+ // 237, // CursorKilled
318
+ // 11601 // Interrupted
319
+ // ]);
320
+
321
+ function isResumableError ( error ) {
322
+ // TODO: Need a way to check if error is
323
+ // - from a getMore
324
+ // - is not in GET_MORE_NON_RESUMABLE_CODES
325
+ if (
326
+ error instanceof MongoNetworkError ||
327
+ RESUMABLE_ERROR_CODES . has ( error . code ) ||
328
+ error . message . match ( / n o t m a s t e r / ) ||
329
+ error . message . match ( / n o d e i s r e c o v e r i n g / )
330
+ ) {
331
+ return true ;
332
+ }
333
+
334
+ return false ;
335
+ }
336
+
299
337
// Handle new change events. This method brings together the routes from the callback, event emitter, and promise ways of using ChangeStream.
300
338
var processNewChange = function ( self , err , change , callback ) {
301
339
// Handle errors
302
340
if ( err ) {
303
341
// Handle resumable MongoNetworkErrors
304
- if ( err instanceof MongoNetworkError && ! self . attemptingResume ) {
342
+ if ( isResumableError ( err ) && ! self . attemptingResume ) {
305
343
self . attemptingResume = true ;
306
344
return self . cursor . close ( function ( closeErr ) {
307
345
if ( closeErr ) {
0 commit comments