Ensure _changeStreamsMonitorStarted is fulfilled under exclusive lock

XMLWordPrintableJSON

    • Cluster Scalability
    • Fully Compatible
    • ALL
    • ClusterScalability 8Jun-22June, ClusterScalability 22Jun-6Jul
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      From a PR comment.

      In ReshardingRecipientService, _changeStreamsMonitorStarted SharedPromise is fulfilled 4 times, three of those times under exclusive lock. But in _createAndStartChangeStreamsMonitor, the promise is fulfilled without holding an exclusive lock.

      Code snippet:

          if (!_metadata.getPerformVerification() || _skipCloningAndApplying ||
              inPotentialAbortScenario(_recipientCtx.getState()) ||
              _changeStreamsMonitorStarted.getFuture().isReady() ||
              _changeStreamsMonitorCompleted.getFuture().isReady()) {
              return;
          }
      
          _createChangeStreamsMonitor(executor, factory);
          _changeStreamsMonitorStarted.emplaceValue();
      

      The check of isReady will catch most cases of double fulfillment, but there is a window here where isReady returns false, but then the SharedPromise is fulfilled before emplaceValue is called. This would cause a exception, as a SharedPromise can only be fulfilled once.

      The fix is to put the isReady/emplaceValue sequence under an exclusive lock.

            Assignee:
            Wenqin Ye
            Reporter:
            Jordan Glassley
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: