-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Process: use overlapped I/O for parent end of stdout/stderr pipes on Windows #125643
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
adamsitnik
merged 7 commits into
main
from
copilot/extend-process-createpipe-with-asyncreads
Mar 18, 2026
+68
−6
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1f2a0b0
Initial plan
Copilot 086df30
Extend Process.CreatePipe with asyncReads for overlapped IO on stdout…
Copilot ac37519
Apply suggestions from code review
adamsitnik 7ed78ce
ensure CreateAnonymousPipe mimics CreatePipe for async pipes:
adamsitnik a33287d
address code review feedback
adamsitnik 369b80f
make sure SafeFileHandle.CreateAnonymousPipe is going to work in Wind…
adamsitnik 659e7c6
address code review feedback
adamsitnik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -640,12 +640,12 @@ ref processInfo // pointer to PROCESS_INFORMATION | |||||
| if (startInfo.RedirectStandardOutput) | ||||||
| { | ||||||
| Encoding enc = startInfo.StandardOutputEncoding ?? GetEncoding((int)Interop.Kernel32.GetConsoleOutputCP()); | ||||||
| _standardOutput = new StreamReader(new FileStream(parentOutputPipeHandle!, FileAccess.Read, 4096, false), enc, true, 4096); | ||||||
| _standardOutput = new StreamReader(new FileStream(parentOutputPipeHandle!, FileAccess.Read, 4096, parentOutputPipeHandle!.IsAsync), enc, true, 4096); | ||||||
| } | ||||||
| if (startInfo.RedirectStandardError) | ||||||
| { | ||||||
| Encoding enc = startInfo.StandardErrorEncoding ?? GetEncoding((int)Interop.Kernel32.GetConsoleOutputCP()); | ||||||
| _standardError = new StreamReader(new FileStream(parentErrorPipeHandle!, FileAccess.Read, 4096, false), enc, true, 4096); | ||||||
| _standardError = new StreamReader(new FileStream(parentErrorPipeHandle!, FileAccess.Read, 4096, parentErrorPipeHandle!.IsAsync), enc, true, 4096); | ||||||
| } | ||||||
|
|
||||||
| commandLine.Dispose(); | ||||||
|
|
@@ -807,9 +807,13 @@ private SafeProcessHandle GetProcessHandle(int access, bool throwIfExited = true | |||||
| // methods such as WriteLine as well as native CRT functions like printf) which are making an | ||||||
| // assumption that the console standard handles (obtained via GetStdHandle()) are opened | ||||||
| // for synchronous I/O and hence they can work fine with ReadFile/WriteFile synchronously! | ||||||
| // We therefore only open the parent's end of the pipe for async I/O (overlapped), while the | ||||||
| // child's end is always opened for synchronous I/O so the child process can use it normally. | ||||||
| private static void CreatePipe(out SafeFileHandle parentHandle, out SafeFileHandle childHandle, bool parentInputs) | ||||||
| { | ||||||
| SafeFileHandle.CreateAnonymousPipe(out SafeFileHandle readHandle, out SafeFileHandle writeHandle); | ||||||
| // Only the parent's read end benefits from async I/O; stdin is always sync. | ||||||
| // asyncRead applies to the read handle; asyncWrite to the write handle. | ||||||
| SafeFileHandle.CreateAnonymousPipe(out SafeFileHandle readHandle, out SafeFileHandle writeHandle, asyncRead: !parentInputs, asyncWrite: false); | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In few weeks from now I will be on parental leave. If this PR introduced a bug, the only thing that needs to be reverted is following line:
Suggested change
And an update for the introduced test. The other changes in this PR are bug fixes. |
||||||
|
|
||||||
| // parentInputs=true: parent writes to pipe, child reads (stdin redirect). | ||||||
| // parentInputs=false: parent reads from pipe, child writes (stdout/stderr redirect). | ||||||
|
|
||||||
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.