fix: don't run DedicatedThreadExecutor continuations inline on the dedicated thread - #6898
Conversation
…dicated thread #6886 moved TaskCompletionSource completion out of the message pump into the thread's finally block, after the SynchronizationContext is restored to null. With no context in place, awaiting continuations became eligible to run inline, so the engine resumed on the STA thread and ran later tests (e.g. STAThreadTests.Without_STA) there. This broke the Windows engine tests. Create the TaskCompletionSource with RunContinuationsAsynchronously.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review. 📝 WalkthroughWalkthrough
ChangesDedicated thread continuation behavior
Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix Suggested reviewers: Merge Risk: ⚪ Minimal · up to This change prevents await continuations from running inline on the dedicated thread after cleanup, and its regression test exercises that path. No merge-blocking risk is evident. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to The change keeps test execution and cleanup on the dedicated thread while preventing awaiting code from continuing inline on that thread. No new security exposure was identified, but broader security coverage is incomplete. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. A rabbit checks the thread-bound queue, Comment |
|
Verdict: LGTM — small, well-targeted fix with a regression test that actually reproduces the bug. Correctness The root-cause analysis in the description checks out against the code. In This is also consistent with the existing pattern already in the same file: Test
Minor, non-blocking observation Not something to fix in this PR, but worth a mental note for later: this bug class (a |
|
Problem
Windows
modularpipelinehas failed on every run since #6886 (e.g. runs 36239899462, 36280870460, 36313464262). The failing test isTUnit.Engine.Tests.ExpectedStateTests.Pass, in both AOT and reflection modes, becauseSTAThreadTests.Without_STAfails about 13 times per run:Cause
#6886 moved
TaskCompletionSourcecompletion out of the message pump and into the dedicated thread'sfinallyblock. That block runs afterSynchronizationContexthas been restored tonull. Before #6886, the dedicated context was still current when the TCS completed, so the runtime would not inline awaiting continuations. With no context, the engine'sawaitcontinuation now runs inline on the STA thread. The engine then keeps executing on that thread and runs later non-STA tests there.Fix
Create the TCS with
TaskCreationOptions.RunContinuationsAsynchronously. The CleanUp-before-completion ordering from #6886 stays as it was.Tests
DedicatedThreadExecutorTests.Continuation_DoesNotRunOnDedicatedThread. It fails without the fix and passes with it.DedicatedThreadExecutorTests: 9/9 pass.TUnit.TestProject/*/*/STAThreadTests/*: 1515/1515 pass on Windows, net10.0.Issue6361InstanceMethodDataSourceIsolationTests: pass. This test showed as a 4-minute[slow]test in the failing CI runs.Summary by CodeRabbit