ExportXMLWordPrintableJSON

    • Type: Bug
    • Resolution: Unresolved
    • Priority: Major - P3
    • 9.1.0-rc0, 9.1.0-rc1026
    • Affects Version/s: None
    • Component/s: None
    • None
    • Query Execution
    • ALL
    • QE 2026-11-23
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Item 1 of SERVER-138793. sweepQueuedOperationsForMemoryPressure (query_memory_load_shedding.cpp:475) runs on the monitor thread. For each client it takes the ClientLock, then calls QueryLifespan::getIfExists(opCtx) (line 504) and getOpState(opCtx) (line 507). Both read the lifespan slot, a plain std::shared_ptr decoration on the OperationContext.

      The op's own thread writes that slot without the ClientLock: QueryLifespan::get() (lazy create), bind(), and the AlternativeQueryRegion constructor and destructor, which getMore setup uses (getmore_cmd.cpp:386). The isQueuedReader check before the read is an atomic in Locker, so the op can be granted a ticket right after the check. Nothing orders the sweep's read against the op's write. On a lost race the sweep can read a lifespan that was just freed, or create one from the monitor thread.

      Confirmed with a unit test under --config=dbg_tsan (test attached in a comment). One thread swaps the slot through AlternativeQueryRegion. A second thread holds the ClientLock and reads through getIfExists and the decoration. TSAN reports a data race between AlternativeQueryRegion::AlternativeQueryRegion and QueryLifespan::getIfExists, and the reader holds the ClientLock. This reproduces the access pattern; it does not reproduce a crash in the real sweep.

      Proposed fix: stop reading the slot from the sweep. Keep the shed eligibility flag and dt baseline in state that the op thread publishes on the CurOp or OperationContext, which the sweep already reads for tracked bytes (CurOp::getInUseTrackedMemoryBytes). The fields are already atomic. This is also the smaller change to backport. Making slot writes take the ClientLock would fix it at the slot and let SERVER-136425 close, but it touches get(), bind() and the region for every caller.

      Open point: the state must survive getMores and idle periods, which is why it lives on the lifespan today. How the op thread republishes it on each getMore is not designed yet.

            Assignee:
            Zixuan Zhuang
            Reporter:
            Zixuan Zhuang
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: