Skip to content

Commit

Permalink
fix: remove check for NonResumableChangeStreamError label
Browse files Browse the repository at this point in the history
The isResumableError function should not check for the
NonResumableChangeStreamError label. 

NODE-2565
  • Loading branch information
emadum authored Apr 17, 2020
1 parent bee0aa2 commit 7cf669d
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 41 deletions.
6 changes: 1 addition & 5 deletions lib/cursor/core_cursor.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { collationNotSupported, SUPPORTS, MongoDBNamespace } = require('../utils'
const executeOperation = require('../operations/execute_operation');
const { Readable } = require('stream');
const { OperationBase } = require('../operations/operation');
const { MongoError, MongoNetworkError, mongoErrorContextSymbol } = require('../error');
const { MongoError, MongoNetworkError } = require('../error');
const {
BSON: { Long }
} = require('../deps');
Expand Down Expand Up @@ -793,10 +793,6 @@ function nextFunction(self, callback) {
// Execute the next get more
self._getMore(function(err, doc, connection) {
if (err) {
if (err instanceof MongoError) {
err[mongoErrorContextSymbol].isGetMore = true;
}

return handleCallback(callback, err);
}

Expand Down
25 changes: 2 additions & 23 deletions lib/error.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
'use strict';

const mongoErrorContextSymbol = Symbol('mongoErrorContextSymbol');
const kErrorLabels = Symbol('errorLabels');
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
Expand Down Expand Up @@ -60,7 +55,6 @@ class MongoError extends Error {
}

this.name = 'MongoError';
this[mongoErrorContextSymbol] = this[mongoErrorContextSymbol] || {};
}

/**
Expand Down Expand Up @@ -343,17 +337,7 @@ function isNetworkTimeoutError(err) {
//
// 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, wireVersion) {
if (!isGetMoreError(error)) {
return false;
}

if (error instanceof MongoNetworkError) {
return true;
}
Expand All @@ -362,22 +346,17 @@ function isResumableError(error, wireVersion) {
return error.hasErrorLabel('ResumableChangeStreamError');
}

return (
GET_MORE_RESUMABLE_CODES.has(error.code) &&
!error.hasErrorLabel('NonResumableChangeStreamError')
);
return GET_MORE_RESUMABLE_CODES.has(error.code);
}

module.exports = {
GET_MORE_NON_RESUMABLE_CODES,
GET_MORE_RESUMABLE_CODES,
MongoError,
MongoNetworkError,
MongoParseError,
MongoTimeoutError,
MongoServerSelectionError,
MongoWriteConcernError,
mongoErrorContextSymbol,
isRetryableError,
isSDAMUnrecoverableError,
isNodeShuttingDownError,
Expand Down
14 changes: 1 addition & 13 deletions test/functional/change_stream.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
'use strict';
const assert = require('assert');
const { Transform } = require('stream');
const {
MongoError,
MongoNetworkError,
mongoErrorContextSymbol,
isResumableError
} = require('../../lib/error');
const { MongoError, MongoNetworkError } = require('../../lib/error');
const { setupDatabase, delay } = require('./shared');
const co = require('co');
const mock = require('mongodb-mock-server');
Expand All @@ -31,7 +26,6 @@ function triggerResumableError(changeStream, onCursorClosed) {
changeStream.cursor.close(callback);
};
const fakeResumableError = new MongoNetworkError('fake error');
fakeResumableError[mongoErrorContextSymbol] = { isGetMore: true };
changeStream.cursor.emit('error', fakeResumableError);
}

Expand Down Expand Up @@ -2798,9 +2792,3 @@ describe('Change Streams', function() {
});
});
});

describe('Change Stream Resume Error Tests', function() {
it('should properly process errors that lack the `mongoErrorContextSymbol`', function() {
expect(() => isResumableError(new Error())).to.not.throw();
});
});

0 comments on commit 7cf669d

Please sign in to comment.