Repository navigation
Conversation
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The narrow changes address the identified synchronization gaps while preserving existing queue locking and callback behavior.
No open issues 🎉
What changed in this PR
This PR addresses #15308 by tightening synchronization around the WinForms Control callback queue used to marshal work to the UI thread.
Changes:
- Marks the lazily initialized queue reference
volatilefor safe publication. - Removes the unlocked queue-count check during disposal handling, retaining the check inside the queue lock.
| File | Description |
|---|---|
src/System.Windows.Forms/System/Windows/Forms/Control.cs |
Ensures safe queue publication and removes an unsynchronized count read. |
Review effort: Balanced
LeafShi1
requested review from
KlausLoeffelmann,
Shyam-Gupta,
SimonZhao888 and
ricardobossan
October 26, 2026 09:31
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #15311 +/- ##
=============================================
Coverage 37.84861% 37.84861%
=============================================
Files 246 246
Lines 9789 9789
Branches 1031 1031
=============================================
Hits 3705 3705
Misses 5920 5920
Partials 164 164
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
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.
Fixes #15308
Root cause
The callback queue is lazily initialized under an instance lock, but readers access the queue reference without acquiring that initialization lock. Consequently, the initialization lock alone does not establish safe publication to those readers.
Additionally, the disposal path reads the queue's Count outside the queue lock, even though other threads may modify the queue.
Proposed change
volatileto the callback queue field so other threads can safely access the initialized queueCustomer Impact
Regression?
Risk
Test environment(s)
Microsoft Reviewers: Open in CodeFlow