fix: pin Task.Factory.StartNew to TaskScheduler.Default (#4071)#4079
Merged
iancooper merged 2 commits intoBrighterCommand:masterfrom Apr 26, 2026
Merged
Conversation
…and#4071) Dispatcher.Start, Performer.Run, TimeoutPolicyHandler, and the Mediator Runner/Waker called Task.Factory.StartNew without an explicit scheduler, inheriting TaskScheduler.Current. Under any limited-concurrency scheduler (BrighterAsyncContext, ASP.NET, async test hosts), the spawned tasks queued behind the very thread waiting for them and End() / await never returned. LongRunning is only a hint — only TaskScheduler.Default guarantees a fresh thread. Pass TaskScheduler.Default explicitly at every affected call site and add a regression test using ConcurrentExclusiveSchedulerPair that deadlocks without the fix.
0316ae3 to
203740e
Compare
There was a problem hiding this comment.
Gates Passed
4 Quality Gates Passed
See analysis details in CodeScene
Quality Gate Profile: Clean Code Collective
Install CodeScene MCP: safeguard and uplift AI-generated code. Catch issues early with our IDE extension and CLI tool.
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.
Closes #4071.
Summary
Dispatcher.Start,Performer.Run,TimeoutPolicyHandler,Mediator.Runner, andMediator.WakercalledTask.Factory.StartNewwithout an explicitTaskScheduler, inheritingTaskScheduler.Current. Under any limited-concurrency scheduler (BrighterAsyncContext, ASP.NET, async test hosts), the control task / message pump queued behind the very thread waiting for them andEnd()/awaitnever returned.TaskCreationOptions.LongRunningis only a hint — onlyTaskScheduler.Defaultguarantees a fresh thread.TaskScheduler.Defaultexplicitly at every affected call site.Performer.Runalso dropped its redundantasync/awaitwrapper.DispatcherOnLimitedConcurrencySchedulerTestsusingConcurrentExclusiveSchedulerPair— verified red without the fix (30 s deadlock) and green with it (~600 ms).Test plan
TaskCreationOptions.LongRunning-only call (deadlock at 30 s) and passes withTaskScheduler.Defaultpin.MessageDispatchtests pass onnet9.0.net9.0(2 pre-existing skips on obsolete Timeout API).Paramore.Brighter.ServiceActivatorandParamore.Brighter.Mediatorbuild clean.