Skip to content

Conversation

@eduardo-vp
Copy link
Member

@eduardo-vp eduardo-vp commented Jan 13, 2026

The thread pool is currently not alternating between high-priority and normal-priority work items.

@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @mangod9
See info in area-owners.md if you want to be subscribed.

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 bug in the thread pool's priority alternation mechanism. The issue was that the flag controlling whether to dispatch normal-priority work first was only being toggled when certain conditions were met, rather than on every dequeue attempt. This prevented proper alternation and could lead to starvation of normal-priority work items.

Changes:

  • Moved the toggle of _dispatchNormalPriorityWorkFirst flag outside the conditional block to ensure it happens on every call to DequeueWithPriorityAlternation

@jkotas jkotas requested a review from VSadov January 13, 2026 18:39
@jkotas
Copy link
Member

jkotas commented Jan 13, 2026

Is this a recent regression?

@eduardo-vp
Copy link
Member Author

It seems that the bug was introduced when the time-sensitive work item queue was removed and just the high-priority queue was used instead in #64834.

@agocke
Copy link
Member

agocke commented Jan 14, 2026

If this is in 10 and we need a backport we'll need a writeup of the full issue for triage.

@VSadov
Copy link
Member

VSadov commented Jan 14, 2026

Considering that it has not been noticed so far (since net7.0 ?), I wonder if the difference has a material impact at all or whether we have a way to measure it.
Does the fix make a difference on TE or on some other benchmarks?

@mangod9
Copy link
Member

mangod9 commented Jan 14, 2026

yeah would be good to know if this is fixing a perf or a functional issue?

@eduardo-vp
Copy link
Member Author

I see that this code for the time-sensitive work item queue was introduced in #61930 as a fix for #61804. Looks like in .NET 6 without this queue it was possible to end up with starved worker threads with the timer callbacks not being able to run.

However, I checked that the issue doesn't repro in .NET 8, 9 and 10. In that case, rather than enabling the priority alternation, I guess that logic can be removed as well since we haven't seen starvation issues as described in #61804 and naturally high priority work items are preferred.

@eduardo-vp
Copy link
Member Author

Since the priority alternation was introduced to solve #61804 but even without it that's no longer an issue, I think it should be safe to remove it as we were not using it anyway for the past releases.

@jkotas
Copy link
Member

jkotas commented Jan 24, 2026

cc @stephentoub

@mangod9
Copy link
Member

mangod9 commented Jan 24, 2026

so assume this doesnt have any perf implications correct?

@agocke
Copy link
Member

agocke commented Jan 24, 2026

Can we run te/other benchmarks before merging?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants