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 |
|
Updated [TUnit](https://github.com/thomhurst/TUnit) from 1.68.17 to 1.70.1. <details> <summary>Release notes</summary> _Sourced from [TUnit's releases](https://github.com/thomhurst/TUnit/releases)._ ## 1.70.1 <!-- Release notes generated using configuration in .github/release.yml at v1.70.1 --> ## What's Changed ### Other Changes * fix: don't run DedicatedThreadExecutor continuations inline on the dedicated thread by @thomhurst in thomhurst/TUnit#6898 **Full Changelog**: thomhurst/TUnit@v1.70.0...v1.70.1 ## 1.70.0 <!-- Release notes generated using configuration in .github/release.yml at v1.70.0 --> ## What's Changed ### Other Changes * feat: clear parallel constraints and limiter during test registration by @thomhurst in thomhurst/TUnit#6897 * fix(mocks): emit valid lambdas for Task/ValueTask-returning delegate mocks by @thomhurst in thomhurst/TUnit#6896 ### Dependencies * chore(deps): update tunit to 1.69.24 by @thomhurst in thomhurst/TUnit#6893 **Full Changelog**: thomhurst/TUnit@v1.69.24...v1.70.0 ## 1.69.24 <!-- Release notes generated using configuration in .github/release.yml at v1.69.24 --> ## What's Changed ### Other Changes * fix: skip Ctrl+C handling where Console.CancelKeyPress is unsupported by @glennawatson in thomhurst/TUnit#6889 ### Dependencies * chore(deps): update verify to 33.1.5 by @thomhurst in thomhurst/TUnit#6891 * chore(deps): update tunit to 1.69.21 by @thomhurst in thomhurst/TUnit#6890 **Full Changelog**: thomhurst/TUnit@v1.69.21...v1.69.24 ## 1.69.21 <!-- Release notes generated using configuration in .github/release.yml at v1.69.21 --> ## What's Changed ### Other Changes * fix: preserve JUnit results after session cancellation by @Sing303 in thomhurst/TUnit#6882 * feat: warn when setup hooks pass the test execution token by @Sing303 in thomhurst/TUnit#6883 * fix: complete DedicatedThreadExecutor tests only after CleanUp() returns by @glennawatson in thomhurst/TUnit#6886 ### Dependencies * chore(deps): update tunit to 1.69.16 by @thomhurst in thomhurst/TUnit#6881 ## New Contributors * @glennawatson made their first contribution in thomhurst/TUnit#6886 **Full Changelog**: thomhurst/TUnit@v1.69.16...v1.69.21 ## 1.69.16 <!-- Release notes generated using configuration in .github/release.yml at v1.69.16 --> ## What's Changed ### Other Changes * fix: preserve TRX results when session cleanup fails by @Sing303 in thomhurst/TUnit#6879 ### Dependencies * chore(deps): update tunit to 1.69.0 by @thomhurst in thomhurst/TUnit#6864 * chore(deps): update dependency messagepack to 3.1.10 by @thomhurst in thomhurst/TUnit#6866 * chore(deps): update dependency dompurify to v3.4.16 by @thomhurst in thomhurst/TUnit#6867 * chore(deps): update dependency serialize-javascript to v7.1.2 by @thomhurst in thomhurst/TUnit#6868 * chore(deps): update dependency azure.data.tables to 12.13.0 by @thomhurst in thomhurst/TUnit#6870 * chore(deps): update dependency microsoft.playwright to 1.63.0 by @thomhurst in thomhurst/TUnit#6871 * chore(deps): update verify to 33.1.2 by @thomhurst in thomhurst/TUnit#6872 * chore(deps): update dependency verify.tool to v0.9.2 by @thomhurst in thomhurst/TUnit#6873 * chore(deps): update verify to 33.1.3 by @thomhurst in thomhurst/TUnit#6874 * chore(deps): update verify to 33.1.4 by @thomhurst in thomhurst/TUnit#6876 * chore(deps): update dependency moq to 4.21.0 by @thomhurst in thomhurst/TUnit#6877 * chore(deps): bump image-size from 2.0.2 to 2.0.4 in /docs by @dependabot[bot] in thomhurst/TUnit#6878 ## New Contributors * @Sing303 made their first contribution in thomhurst/TUnit#6879 **Full Changelog**: thomhurst/TUnit@v1.69.0...v1.69.16 ## 1.69.0 <!-- Release notes generated using configuration in .github/release.yml at v1.69.0 --> ## What's Changed ### Other Changes * feat(templates): add enableDotCover flag (#6714) by @ForNeVeR in thomhurst/TUnit#6844 * fix: don't request semantic models for attribute syntax from other compilations (DevKit crash) by @thomhurst in thomhurst/TUnit#6855 * fix(ci): restore net472 PublicAPI tests on Windows by @thomhurst in thomhurst/TUnit#6857 * perf(html-report): stream report JSON through pooled chunks and overlap sidecar serialization by @thomhurst in thomhurst/TUnit#6860 * chore(renovate): cap Microsoft.Build packages below 18.10.0 by @thomhurst in thomhurst/TUnit#6863 * perf: shrink generated per-class test source static constructors (~40% less startup JIT) by @thomhurst in thomhurst/TUnit#6859 * refactor: remove unreachable decimal source-text path from GenerateAttributeInstantiation by @thomhurst in thomhurst/TUnit#6856 * perf: cut per-test allocations in discovery and execution (-61% at 10k tests) by @thomhurst in thomhurst/TUnit#6861 * perf: stop hashing per-test event receivers during registration (data-driven tests 2.9x faster at 10k) by @thomhurst in thomhurst/TUnit#6858 * perf(analyzers): cut TUnit analyzer build time ~60% on large test projects by @thomhurst in thomhurst/TUnit#6862 ### Dependencies * chore(deps): update opentelemetry to 1.19.0 by @thomhurst in thomhurst/TUnit#6838 * chore(deps): update dependency opentelemetry.instrumentation.runtime to 1.19.0 by @thomhurst in thomhurst/TUnit#6840 * chore(deps): update tunit to 1.68.17 by @thomhurst in thomhurst/TUnit#6839 * chore(deps): update verify to 33.1.0 by @thomhurst in thomhurst/TUnit#6843 * chore(deps): update verify to 33.1.1 by @thomhurst in thomhurst/TUnit#6847 * chore(deps): update opentelemetry to 1.19.1 by @thomhurst in thomhurst/TUnit#6850 * chore(deps): update dependency grpc.core.api to 2.84.0 by @thomhurst in thomhurst/TUnit#6851 * chore(deps): update dependency stackexchange.redis to 3.3.1 by @thomhurst in thomhurst/TUnit#6853 * chore(deps): update dependency polyfill to 11.4.0 by @thomhurst in thomhurst/TUnit#6841 * chore(deps): update dependency polyfill to 11.4.0 by @thomhurst in thomhurst/TUnit#6842 ## New Contributors * @ForNeVeR made their first contribution in thomhurst/TUnit#6844 **Full Changelog**: thomhurst/TUnit@v1.68.17...v1.69.0 Commits viewable in [compare view](thomhurst/TUnit@v1.68.17...v1.70.1). </details> [](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) </details> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Updated [TUnit](https://github.com/thomhurst/TUnit) from 1.69.16 to 1.70.1. <details> <summary>Release notes</summary> _Sourced from [TUnit's releases](https://github.com/thomhurst/TUnit/releases)._ ## 1.70.1 <!-- Release notes generated using configuration in .github/release.yml at v1.70.1 --> ## What's Changed ### Other Changes * fix: don't run DedicatedThreadExecutor continuations inline on the dedicated thread by @thomhurst in thomhurst/TUnit#6898 **Full Changelog**: thomhurst/TUnit@v1.70.0...v1.70.1 ## 1.70.0 <!-- Release notes generated using configuration in .github/release.yml at v1.70.0 --> ## What's Changed ### Other Changes * feat: clear parallel constraints and limiter during test registration by @thomhurst in thomhurst/TUnit#6897 * fix(mocks): emit valid lambdas for Task/ValueTask-returning delegate mocks by @thomhurst in thomhurst/TUnit#6896 ### Dependencies * chore(deps): update tunit to 1.69.24 by @thomhurst in thomhurst/TUnit#6893 **Full Changelog**: thomhurst/TUnit@v1.69.24...v1.70.0 ## 1.69.24 <!-- Release notes generated using configuration in .github/release.yml at v1.69.24 --> ## What's Changed ### Other Changes * fix: skip Ctrl+C handling where Console.CancelKeyPress is unsupported by @glennawatson in thomhurst/TUnit#6889 ### Dependencies * chore(deps): update verify to 33.1.5 by @thomhurst in thomhurst/TUnit#6891 * chore(deps): update tunit to 1.69.21 by @thomhurst in thomhurst/TUnit#6890 **Full Changelog**: thomhurst/TUnit@v1.69.21...v1.69.24 ## 1.69.21 <!-- Release notes generated using configuration in .github/release.yml at v1.69.21 --> ## What's Changed ### Other Changes * fix: preserve JUnit results after session cancellation by @Sing303 in thomhurst/TUnit#6882 * feat: warn when setup hooks pass the test execution token by @Sing303 in thomhurst/TUnit#6883 * fix: complete DedicatedThreadExecutor tests only after CleanUp() returns by @glennawatson in thomhurst/TUnit#6886 ### Dependencies * chore(deps): update tunit to 1.69.16 by @thomhurst in thomhurst/TUnit#6881 ## New Contributors * @glennawatson made their first contribution in thomhurst/TUnit#6886 **Full Changelog**: thomhurst/TUnit@v1.69.16...v1.69.21 Commits viewable in [compare view](thomhurst/TUnit@v1.69.16...v1.70.1). </details> Updated [TUnit.AspNetCore](https://github.com/thomhurst/TUnit) from 1.69.16 to 1.70.1. <details> <summary>Release notes</summary> _Sourced from [TUnit.AspNetCore's releases](https://github.com/thomhurst/TUnit/releases)._ ## 1.70.1 <!-- Release notes generated using configuration in .github/release.yml at v1.70.1 --> ## What's Changed ### Other Changes * fix: don't run DedicatedThreadExecutor continuations inline on the dedicated thread by @thomhurst in thomhurst/TUnit#6898 **Full Changelog**: thomhurst/TUnit@v1.70.0...v1.70.1 ## 1.70.0 <!-- Release notes generated using configuration in .github/release.yml at v1.70.0 --> ## What's Changed ### Other Changes * feat: clear parallel constraints and limiter during test registration by @thomhurst in thomhurst/TUnit#6897 * fix(mocks): emit valid lambdas for Task/ValueTask-returning delegate mocks by @thomhurst in thomhurst/TUnit#6896 ### Dependencies * chore(deps): update tunit to 1.69.24 by @thomhurst in thomhurst/TUnit#6893 **Full Changelog**: thomhurst/TUnit@v1.69.24...v1.70.0 ## 1.69.24 <!-- Release notes generated using configuration in .github/release.yml at v1.69.24 --> ## What's Changed ### Other Changes * fix: skip Ctrl+C handling where Console.CancelKeyPress is unsupported by @glennawatson in thomhurst/TUnit#6889 ### Dependencies * chore(deps): update verify to 33.1.5 by @thomhurst in thomhurst/TUnit#6891 * chore(deps): update tunit to 1.69.21 by @thomhurst in thomhurst/TUnit#6890 **Full Changelog**: thomhurst/TUnit@v1.69.21...v1.69.24 ## 1.69.21 <!-- Release notes generated using configuration in .github/release.yml at v1.69.21 --> ## What's Changed ### Other Changes * fix: preserve JUnit results after session cancellation by @Sing303 in thomhurst/TUnit#6882 * feat: warn when setup hooks pass the test execution token by @Sing303 in thomhurst/TUnit#6883 * fix: complete DedicatedThreadExecutor tests only after CleanUp() returns by @glennawatson in thomhurst/TUnit#6886 ### Dependencies * chore(deps): update tunit to 1.69.16 by @thomhurst in thomhurst/TUnit#6881 ## New Contributors * @glennawatson made their first contribution in thomhurst/TUnit#6886 **Full Changelog**: thomhurst/TUnit@v1.69.16...v1.69.21 Commits viewable in [compare view](thomhurst/TUnit@v1.69.16...v1.70.1). </details> Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) </details> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
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