Add safeguard to prevent potentially endless loop in HandleTopologyChangeV2 stage

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Unresolved
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Query Execution
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      The PR for SERVER-106575 (in progress) will add the following code:

      DocumentSource::GetNextResult ChangeStreamHandleTopologyChangeV2Stage::doGetNext() {
          // Continue advancing the state until there is either an event to return or an exception is
          // thrown.
          for (;;) {
              auto event = _runGetNextStateMachine();
              if (event.has_value()) {
                  return *event;
              }
          }
      }
      

      While great care has been taken to make sure that the state machine will eventually produce an event and exit the loop, in theory it is possible that this loop will never end.
      In case this actually happens, this would clog up an entire mongos thread forever, which is obviously undesired.
      We should therefore add either an iteration-count or time-based exit mechanism to this loop, after which the loop produces an EOF. The preference is a time-based mechanism. The specifics of this have to be worked out.
      This change can be done after the changes from SERVER-106575 have landed. The new code is only used in v2 change streams, which are currently only enabled when a feature flag is set and only if the caller opts in (which currently does not happen outside of tests).

            Assignee:
            Jan Steemann
            Reporter:
            Jan Steemann
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: