-
Notifications
You must be signed in to change notification settings - Fork 5k
[Mono] Fix wait's returning false on non-runtime queued user APC's. #116001
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
Merged
steveisok
merged 5 commits into
dotnet:main
from
lateralusX:lateralusX/fix-wait-break-on-apc
May 28, 2025
Merged
[Mono] Fix wait's returning false on non-runtime queued user APC's. #116001
steveisok
merged 5 commits into
dotnet:main
from
lateralusX:lateralusX/fix-wait-break-on-apc
May 28, 2025
Conversation
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
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 ensures that waits aren’t broken by non-runtime queued user APCs in Mono on Windows and adds a new regression test for this scenario.
- Introduce a new isolated test project and test (
115178
) to validate user APC behavior. - Change
mono_win32_leave_*
functions to return a boolean flag and update their implementations. - Update
win32_wait_for_single_object_ex
andwin32_wait_for_multiple_objects_ex
to loop onWAIT_IO_COMPLETION
, adjust timeouts, and ignore non-runtime APCs.
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
src/tests/baseservices/threading/regressions/115178/115178.csproj | Add a process-isolated test project for the new regression. |
src/tests/baseservices/threading/regressions/115178/115178.cs | Implement new regression test for user APC–interrupted waits. |
src/mono/mono/utils/mono-threads.h | Change prototypes of leave functions to return gboolean . |
src/mono/mono/utils/mono-threads-windows.c | Update leave implementations to return alert status. |
src/mono/mono/utils/mono-os-wait-win32.c | Add looping logic around WAIT_IO_COMPLETION and time accounting. |
Comments suppressed due to low confidence (1)
src/mono/mono/utils/mono-os-wait-win32.c:65
- [nitpick] The enter-wait macro uses 'interrupted' but the leave-wait uses 'alerted'; consider unifying on one term (e.g. 'alerted') to reduce cognitive load.
gboolean interrupted = FALSE;
jkotas
reviewed
May 26, 2025
steveisok
approved these changes
May 27, 2025
BrzVlad
approved these changes
May 27, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
needs-area-label
An area label is needed to ensure this gets routed to the appropriate area owners
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.
Mono's internal interrupt handling uses user APC to break waits in case runtime needs to interrupt threads. If that happens, wait will return false. For API's like
ManualResetEventSlim.Wait()
withvoid
return, this can cause issues if the wait is broken prematurely. If a user APC have been queued to the thread, not triggered by internal runtime interrupt handling, it would lead to unexpected side effects.Fix makes sure runtime ignores returns from WaitForSingleObjectEx/WaitForMultipleObjectsEx due to APC completions not initialized by runtime.
Fix also adds a new runtime test to trigger this scenario for Mono runtime on Windows.
Fixes #115178.