Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Closed

Conversation

@RSoeborg
Copy link

@RSoeborg RSoeborg commented Oct 20, 2025
edited
Loading

Summary of the changes (Less than 80 chars)

Fix BatchDispatcher spin loop starvation when pool is saturated

  1. Added pending-work guard to headroom probe
  2. Yield after spin window to release worker threads
  3. Added regression test covering thread pool saturation

Closes #8825

@Copilot Copilot AI review requested due to automatic review settings October 20, 2025 13:37
Copy link

CLAassistant commented Oct 20, 2025
edited
Loading

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

Copilot AI left a 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.


Assert.True(started.Wait(TimeSpan.FromSeconds(10)), "Blocking tasks failed to start.");

var extraTasks = new Task[blockerCount * 8];
Copy link

Copilot AI Oct 20, 2025

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.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

Copilot code review Copilot Copilot left review comments

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

BatchDispatcher spins under load after v16 upgrade, starving worker threads

AltStyle によって変換されたページ (->オリジナル) /