-
-
Notifications
You must be signed in to change notification settings - Fork 798
Fix BatchDispatcher headroom detection under thread pool saturation #8826
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
CLA assistant check
All committers have signed the CLA.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes a thread pool saturation issue in BatchDispatcher by preventing spin loops from starving worker threads and improving headroom detection. The changes address a scenario where the dispatcher could get stuck in a busy wait when all worker threads are occupied.
- Added pending work item check to headroom detection for more accurate thread pool state assessment
- Added Thread.Yield() after spin windows to prevent worker thread starvation
- Added comprehensive regression test to verify the fix under thread pool saturation conditions
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| BatchDispatcher.cs | Enhanced headroom detection with pending work guard and added yield to prevent spin loop starvation |
| BatchDispatcherTests.cs | Added regression test that saturates thread pool and validates headroom detection behavior |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Copilot
AI
Oct 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The magic number 8 used as a multiplier lacks explanation. Consider extracting this to a named constant with a comment explaining why this specific multiplier is needed to create sufficient thread pool pressure.
Uh oh!
There was an error while loading. Please reload this page.
Summary of the changes (Less than 80 chars)
Fix BatchDispatcher spin loop starvation when pool is saturated
Closes #8825