Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-102422

Remove invariant in AsyncResultsMerger destructor

    • Query Execution
    • Fully Compatible
    • v8.1, v8.0
    • QE 2025-03-17
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      The AsyncResultsMerger currently performs an invariant check in its own destructor, checking that the ARM instance has either been already killed (all remote cursor killed) or that all remote cursor have already been fully exhausted.

      In case the invariant is violated, the server process will be crashed, which is pretty damaging.
      Because this is the destructor, we cannot simply change this to a tassert or other throwing assertion type.
      In case it was forgotten to kill the remote cursors before, we cannot do it from the destructor. Killing remote cursors requires an OperationContext pointer, which we do not have access to from inside the destructor.
      There is simply not much we can do here, so we should remove the invariant from the destructor in order to avoid unexpected server crashes when for whatever reason the remote cursors have not been fully killed or exhausted.

      In some previous versions of the AsyncResultsMerger, there were some issues with object lifetimes in case the ARM scheduled some requests to remote shards which were eventually executed in a background thread. When the responses came back and needed to be handled, a lambda was executed that needed access to the AsyncResultsMerger object too. In those previous versions it was possible that the destructor of the AsyncResultsMerger was run before all scheduled requests were reaped, which could lead to the invariant failure being triggered, and also required the AsyncResultsMerger's destructor to acquire the instance's mutex.
      The object lifetime issues have been fixed in SERVER-99905 (PR), so we can now remove all special handling from the ARM's destructor.

            Assignee:
            jan.steemann@mongodb.com Jan Steemann
            Reporter:
            jan.steemann@mongodb.com Jan Steemann
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:
              None
              None
              None
              None