Use TaskScheduler.Default when calling Task.Factory.StartNew#8779
Conversation
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 41534bc4bf
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
41534bc to
ce3b8ba
Compare
BenchmarksBenchmark execution time: 2026-06-11 13:16:16 Comparing candidate commit ce3b8ba in PR branch Found 0 performance improvements and 1 performance regressions! Performance is the same for 70 metrics, 1 unstable metrics, 61 known flaky benchmarks, 65 flaky benchmarks without significant changes.
|
## Summary of changes Uses `TaskScheduler.Default` when calling `Task.Factory.StartNew` ## Reason for change When calling `Task.Factory.StartNew`, if you don't explicitly provide a `TaskScheduler`, it inherits `TaskScheduler.Current` from the calling thread. If there's a custom scheduler, this can cause problems (e.g. same as #8767). That PR fixed the issue for DataStreamsMonitoring, this PR fixes it everywhere else. ## Implementation details - Had 🤖 look for all the cases where we were missing this - _Technically_ there are some `ContinueWith` that should have it too, but in all of the _other_ cases not covered by this PR, those are simply logging on faulted, so it didn't seem worth the hassle - Updated the vendoring code to handle our changes to Statsdclient too - Note that `Task.Run` ignores `TaskScheduler.Current` so it's not a problem ## Test coverage Covered by existing tests, and not worth creating a regression for IMO
Summary of changes
Uses
TaskScheduler.Defaultwhen callingTask.Factory.StartNewReason for change
When calling
Task.Factory.StartNew, if you don't explicitly provide aTaskScheduler, it inheritsTaskScheduler.Currentfrom the calling thread. If there's a custom scheduler, this can cause problems (e.g. same as #8767). That PR fixed the issue for DataStreamsMonitoring, this PR fixes it everywhere else.Implementation details
ContinueWiththat should have it too, but in all of the other cases not covered by this PR, those are simply logging on faulted, so it didn't seem worth the hassleTask.RunignoresTaskScheduler.Currentso it's not a problemTest coverage
Covered by existing tests, and not worth creating a regression for IMO