Fix race condition in System.Threading.Overlapped tests causing IOException on Windows ARM64#127493
Draft
Fix race condition in System.Threading.Overlapped tests causing IOException on Windows ARM64#127493
Conversation
…revent premature finalization Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/233433e7-d3f0-411c-a574-0bfd57ff9e9e Co-authored-by: mangod9 <61718172+mangod9@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix overlapped test failure on Windows ARM64 due to IOException
Fix race condition in System.Threading.Overlapped tests causing IOException on Windows ARM64
Apr 28, 2026
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @VSadov |
This was referenced Apr 28, 2026
Open
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.
Under PGO stress on Windows ARM64,
PackPosTestandPackPosTest1would intermittently crash withIOException: The handle is invalidatEventWaitHandle.Set()inside the IO completion callback.Description
Root cause: The two-stage callback chain queues a second
NativeOverlapped*that holds the only reference tohelperas an unmanaged pointer. The GC cannot trace through unmanaged pointers, so afterhelper.Wait()returns the JIT is free to reporthelperas dead — allowing the finalizer to close theManualResetEventOS handle before the second callback fires and calls_event.Set().Fix: Add
GC.KeepAlive(helper)afterhelper.Wait()in bothPackPosTestandPackPosTest1:This extends
helper's managed lifetime pastWait(), ensuring theManualResetEventhandle remains valid for the entire callback chain. The bug is latent since the test was written; it surfaced only under defaultpgo stress timing on ARM64.Fixes #127366