@resolveio/server-lib 20.14.12 → 20.14.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -79,6 +79,7 @@ export declare class SubscriptionManager {
79
79
  private resolveLocalOplogResyncIntervalMs;
80
80
  private parsePositiveNumber;
81
81
  private isChangeStreamUnsupported;
82
+ private isResumeTokenInvalid;
82
83
  private enableLocalOplogFallback;
83
84
  getUseLocalOplog(): boolean;
84
85
  notifyLocalOplog(collection: string, type?: string): void;
@@ -1038,6 +1038,29 @@ var SubscriptionManager = /** @class */ (function () {
1038
1038
  }
1039
1039
  return false;
1040
1040
  };
1041
+ SubscriptionManager.prototype.isResumeTokenInvalid = function (error) {
1042
+ var code = typeof (error === null || error === void 0 ? void 0 : error.code) === 'number' ? error.code : null;
1043
+ var codeName = typeof (error === null || error === void 0 ? void 0 : error.codeName) === 'string' ? error.codeName.toLowerCase() : '';
1044
+ var message = typeof (error === null || error === void 0 ? void 0 : error.message) === 'string' ? error.message.toLowerCase() : '';
1045
+ if (code === 286) {
1046
+ // ChangeStreamHistoryLost
1047
+ return true;
1048
+ }
1049
+ if (codeName.includes('changestreamhistorylost')) {
1050
+ return true;
1051
+ }
1052
+ if (message.includes('resume token') && (message.includes('not found') ||
1053
+ message.includes('not possible') ||
1054
+ message.includes('no longer') ||
1055
+ message.includes('not in the oplog') ||
1056
+ message.includes('too old'))) {
1057
+ return true;
1058
+ }
1059
+ if (message.includes('resume of change stream') && message.includes('not possible')) {
1060
+ return true;
1061
+ }
1062
+ return false;
1063
+ };
1041
1064
  SubscriptionManager.prototype.enableLocalOplogFallback = function (reason, error) {
1042
1065
  return __awaiter(this, void 0, void 0, function () {
1043
1066
  var _a, message;
@@ -1571,8 +1594,16 @@ var SubscriptionManager = /** @class */ (function () {
1571
1594
  case 1:
1572
1595
  _a.sent();
1573
1596
  return [2 /*return*/];
1574
- case 2: return [4 /*yield*/, this._oplog$.close()];
1597
+ case 2:
1598
+ if (!this.isResumeTokenInvalid(error)) return [3 /*break*/, 4];
1599
+ return [4 /*yield*/, this.clearResumeToken()];
1575
1600
  case 3:
1601
+ _a.sent();
1602
+ lastResumeToken_1 = null;
1603
+ this.queueFullResync('oplog-resume-token-invalid');
1604
+ _a.label = 4;
1605
+ case 4: return [4 /*yield*/, this._oplog$.close()];
1606
+ case 5:
1576
1607
  _a.sent();
1577
1608
  return [2 /*return*/];
1578
1609
  }