Repository navigation
[release/11.0] Allow undisposed async file and pipe handles to be finalized on Windows - #137656
Open
adamsitnik wants to merge 2 commits into
Open
adamsitnik wants to merge 2 commits into
adamsitnik wants to merge 2 commits into
Conversation
… on Windows (dotnet#137507) Resolves dotnet#137501 --------- Copilot-Session: 8cfdacb8-9380-470b-83d0-2598d9255b9b (cherry picked from commit e863295)
|
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: @dotnet/area-system-io |
jozkee
approved these changes
Nov 16, 2026
jozkee
enabled auto-merge (squash)
November 17, 2026 00:11
This was referenced Nov 17, 2026
The tests checked GC reachability right after awaiting an async helper. The helper's continuation references the streams (or the process) until the thread that completed it is done with it, which raced with the GC in the test and made the tests flaky. Use synchronous helpers instead. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 8cfdacb8-9380-470b-83d0-2598d9255b9b
This was referenced Nov 17, 2026
Open
This branch has not been deployed
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.
Backport of #137507 to release/11.0
Description
On Windows, async
SafeFileHandle(used byFileStreamandRandomAccess) and asyncPipeStreaminstances can't be finalized after an async read or write unless they're disposed. Each one rents a reusable value-task source and caches it on the handle or stream for the next operation. The cached source was rooted by itsPreAllocatedOverlapped.Customer Impact
Windows apps that open files or pipes for async I/O and don't dispose them leak one OS handle per object. Examples are
FileStreamwithuseAsync: true,RandomAccesson an async handle, andNamedPipeServerStream/NamedPipeClientStreamwithPipeOptions.Asynchronous. For named pipes, the pipe instance itself stays open. The handles are released only when the process exits, so long-running services that don't dispose these objects accumulate them.Regression
No. The issue has existed since .NET 6 (#51363, #53669).
Testing
New tests were added, all of which fail without the fix.
Risk
Low. The changes are limited to the reusable value-task sources used on Windows for async file and pipe I/O. The sources are still reused (no performance regression), but they reference the safe handle only when they are being used.