fix: Restore thread-local stat writer in MockSharedArbitratorTest#8
Open
jaylisde wants to merge 1 commit into
Open
fix: Restore thread-local stat writer in MockSharedArbitratorTest#8jaylisde wants to merge 1 commit into
jaylisde wants to merge 1 commit into
Conversation
Three tests (globalArbitrationWithoutSpill, globalArbitrationSmallParticipantLargeGrow, and a DEBUG_ONLY test) set the thread-local runtime stat writer to a stack-owned TestRuntimeStatWriter on the main thread via a bare setThreadLocalRunTimeStatWriter() call, but never restore it. localRuntimeStatWriter is a thread_local raw pointer, so once the TestRuntimeStatWriter is destroyed at test exit the pointer dangles. The next test that runs on the main thread and reaches addThreadLocalRuntimeStat (e.g. any global arbitration that calls finishArbitration during growCapacity) dereferences the freed writer and segfaults. The tests pass in isolation but crash when run after one of these, depending on execution order. Use the existing RAII RuntimeStatWriterScopeGuard, which restores the previous writer on destruction, so the thread-local pointer is never left dangling.
jaylisde
force-pushed
the
fix/mock-arbitrator-stat-writer-dangling
branch
from
June 7, 2026 22:57
4be6914 to
f875b0d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Three tests in
MockSharedArbitratorTest(globalArbitrationWithoutSpill,globalArbitrationSmallParticipantLargeGrow, and aDEBUG_ONLYtest) set the thread-local runtime stat writer to a stack-ownedTestRuntimeStatWriteron the main thread via a baresetThreadLocalRunTimeStatWriter(), but never restore it.localRuntimeStatWriteris athread_localraw pointer, so once the writer is destroyed at test exit the pointer dangles. The next test that runs on the main thread and reachesaddThreadLocalRuntimeStat(e.g. any global arbitration callingfinishArbitrationduringgrowCapacity) dereferences the freed writer and segfaults — the tests pass in isolation but crash when run back-to-back, depending on gtest order.gdb backtrace:
Fix
Use the existing RAII
RuntimeStatWriterScopeGuard, which restores the previous writer on destruction, so the thread-local pointer is never left dangling.