Repository navigation
Resume escalation tests through an actor so Thread Sanitizer sees the ordering - #107
Merged
Merged
Conversation
… ordering Two tests resumed an unsafe continuation from a dispatch thread. When the thread resumed it before the test suspended, Thread Sanitizer on macOS missed that the thread's work happened before the test continued, and reported a data race in ManualTaskExecutor.runUntil(_:) on the weekly CI run. The tests now wait on the test Semaphore actor, which the dispatch thread signals from a new task. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HLuVQLVigABunsyxAFtbwu
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #107 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 15 15
Lines 3714 3722 +8
=========================================
+ Hits 3714 3722 +8
🚀 New features to boost your workflow:
|
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.
Requested by Dan · project thread
Summary
The weekly scheduled CI run on main (run 45111712457) failed Thread Sanitizer on macOS. All 205 tests passed, but TSan reported a data race:
ManualTaskExecutor.runUntil(_:)on the test task's threadUnsafeContinuation.resume()on theescalateWaitingTaskdispatch thread, incancelTasks_fifoQueue_whileTaskWaitingForItsTurnIsEscalated_escalatesTaskHoldingTurnWithoutWaitingForCancellationHandlerThe test task can't reach
runUntil(_:)until it has been resumed, so the code is correctly ordered. Most likely the dispatch thread resumed the continuation before the test task suspended on it. The task then keeps running without going through an executor, and that's where the runtime may not report the ordering to TSan. The race window is narrow, so this shows up only rarely.This PR changes test code only. Both tests that used this pattern now wait on the test
Semaphoreactor:TurnsTests.begin_whenWaitingTaskIsEscalatedWhileTaskHoldingTurnRunsCancellationHandler_escalatesTaskHoldingTurnWithoutWaitingForHandlerThe dispatch thread signals the semaphore from a new task after it escalates the waiting task. The semaphore resumes the test only after the test has suspended, and that resume goes through the runtime's annotated enqueue path. The order of the escalation and the cancellation is the same as before.
Testing
I couldn't build these changes in my container because it can't download a Swift toolchain, so this PR's CI is the first build and run. The race window was narrow and never reproduced on demand, so no test can show this fix failing 10 of 10 runs before it.
Generated by Claude Code