Repository navigation
Delete NativeOverlapped pool for Win32ThreadPool - #137800
Merged
Merged
Conversation
The portable threadpool has no pool for NativeOverlapped like this and the lack of it was not identified as a bottleneck. There are pools both under (GCHandle, malloc) and above (FileStream and Sockets instances cache and reuse NativeOverlapped). Fix the race condition in the implementation of the superflous pool by deleting it. The allocation / free of Win32 threadpool NativeOverlapped is still faster than allocation / free of portable threadpool NativeOverlapped even with the pool deleted. Fixes dotnet#137737
|
Azure Pipelines: Successfully started running 3 pipeline(s). 12 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @VSadov |
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
Immediate native-memory and GCHandle reclamation changes unsafe Windows I/O lifetimes, but concurrent allocation/completion, callback-time freeing, and PreAllocatedOverlapped reuse/disposal could not be validated in this environment.
No open issues 🎉
What changed in this PR
Removes the Windows thread pool’s NativeOverlapped pool to eliminate the allocation race described in #137737, replacing pooled reuse with direct allocation and cleanup.
Changes:
- Removes the lock-free free list and shared metadata array.
- Uses a per-allocation
GCHandlefor metadata and explicitly releases pinned handles and native memory. - Deletes reset logic used only by the removed pool.
| File | Description |
|---|---|
src/libraries/System.Private.CoreLib/src/System/Threading/Win32ThreadPoolNativeOverlapped.OverlappedData.cs |
Removes pool-specific reset logic and its unused import. |
src/libraries/System.Private.CoreLib/src/System/Threading/Win32ThreadPoolNativeOverlapped.cs |
Replaces pooling with direct native allocation and handle cleanup. |
Review effort: Balanced
VSadov
reviewed
Nov 18, 2026
Member
Author
|
/backport to release/11.0 |
Contributor
|
Started backporting to |
2 of 4 tasks
JulieLeeMSFT
pushed a commit
that referenced
this pull request
Nov 20, 2026
) Backport of #137800 to release/11.0 /cc @jkotas ## Customer Impact - [x] Customer reported - [ ] Found internally Intermittent crash in async I/O intensive NAOT compiled apps on Windows The root cause is race condition in cache for native overlapped instances used by Win32 thread pool (default for NAOT on Windows). The fix is to delete the cache since it is not effective (there are other caches in the layers above and below). ## Regression - [ ] Yes - [x] No ## Testing Customer provided stress test passed ## Risk Low Co-authored-by: Jan Kotas <[email protected]>
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.
The portable threadpool has no pool for NativeOverlapped like this and the lack of it was not identified as a bottleneck. There are pools both under (GCHandle, malloc) and above (FileStream and Sockets instances cache and reuse NativeOverlapped). Fix the race condition in the implementation of the superflous pool by deleting it.
The allocation / free of Win32 threadpool NativeOverlapped is still faster than allocation / free of portable threadpool NativeOverlapped even with the pool deleted.
Fixes #137737