Add Process.ReadAllTextAsync and ReadAllBytesAsync#126942
Add Process.ReadAllTextAsync and ReadAllBytesAsync#126942
Conversation
…plexing Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/45ece5ba-166f-4418-887f-3ecaba54615e Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
…le fixes needed) Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/45ece5ba-166f-4418-887f-3ecaba54615e Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
…ead of GetAwaiter().GetResult() Replace the async Task-based Windows implementation with proper Win32 overlapped IO: - Allocate NativeOverlapped* with ManualResetEvent for each pipe - Use Interop.Kernel32.ReadFile with overlapped structs - Use WaitHandle.WaitAny for synchronous multiplexing - Use GetOverlappedResult to retrieve bytes read - Use CancelIoEx for timeout cancellation - Add System.Threading.Overlapped project reference - Add ReadFile, GetOverlappedResult, CancelIoEx interop references - Fix nullable warning in Unix implementation Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/8af96aef-e52b-459d-a945-e1159e8be19b Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
…in32Exception Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/8af96aef-e52b-459d-a945-e1159e8be19b Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
…elper method, DangerousAddRef/Release, remove partial Changes: 1. Require both stdout and stderr to be redirected (throw if either is missing) 2. Create ReadPipesToBuffers helper shared between ReadAllText and ReadAllBytes (ReadAllText avoids extra buffer copy by decoding from rented buffers directly) 3. GetSafeFileHandleFromStreamReader now returns an owner SafeHandle; caller uses DangerousAddRef/DangerousRelease to prevent handle disposal during reads 4. Remove partial method declaration; ReadPipes is a regular static method in each platform file (non-nullable parameters since both handles always provided) 5. Update tests: all tests redirect both stdout and stderr; add two new tests for missing-stream validation Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/cd917b13-f344-47c5-ac1e-cfb2c2da34f6 Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
…indows ReadPipes fully unsafe with proper cleanup, use is not null Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/451cf437-2de0-409a-937a-0031c3fa69d4 Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
- refactor the code - restore deleted comments - fix AV bug by setting the lower bit for EventHandle - fix test bug: process argument can't be that long - refactor the tests to use Theories rather than very similar Fact for bytes and text
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…RentLargerBuffer overflow Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/34214748-db27-499b-88ef-23a1af15515f Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
…mode test Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/f6ca8588-63c1-4cd8-aeaf-48c716a4ea11 Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
…rlapped cleanup, new tests, StreamBody->Dummy Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/dac42b05-c591-4e1c-b751-9eadeb376728 Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/dac42b05-c591-4e1c-b751-9eadeb376728 Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
…al in interleaved test Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/560e33ea-a2eb-4f65-a9c9-a2bc3fc32986 Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
…provements, simplified poll check Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/8b364ac1-c21d-4c74-88ca-44d6a5ea4064 Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/7af21a01-1482-4765-91af-d73ea6f088cc Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
…ly official docs references Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/ef4fa489-ab10-4574-9069-ca32ccaac99b Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
…Read with EAGAIN handling Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/2646b5c6-b0ae-4ae3-99ca-064187661e73 Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/9d7b276f-4c66-4ff0-88ee-087b732ad8ce Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/9d7b276f-4c66-4ff0-88ee-087b732ad8ce Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
|
Tagging subscribers to this area: @dotnet/area-system-diagnostics-process |
Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
…rAsync Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/982b6b03-c72f-4637-b412-81362aadb9df Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
|
@copilot please check latest commits, do NOT touch the code, just update the PR description and then invoke the code-review skill and post your analysis/results as a comment on this PR |
PR description updated. Here is the code review: 🤖 Copilot Code Review — PR #126942Holistic AssessmentMotivation: The changes since the merge base ( Approach: The two-task Summary: ✅ LGTM. The implementation is correct, simpler than what it replaces, and handles all buffer lifecycle edge cases properly. Verified by multi-model review (Gemini 2.5 Pro, GPT 5.3 Codex) — zero issues found across both models. Detailed Findings✅ Buffer lifecycle — Correct ownership transfer
✅ Exception handling — Exactly-once buffer returnWhen one task faults and the other succeeds: the faulted task's buffer was returned in ✅ Cancellation — Clean propagation
✅ Performance — Reduced allocationsEliminates per-read ✅ No new public API surface in this diffThe ref assembly was not modified in these commits — new public APIs were added in earlier commits that are already part of the merge base. |
d6c1a3f to
c0c1d8b
Compare
|
@copilot please invoke the code-review skill and post your analysis/results as a comment on this PR |
PR description updated and code review completed. Posting results below. |
🤖 Copilot Code Review — PR #126942Note This review was AI/Copilot-generated. Multi-model review: primary analysis by Claude Opus 4.6, cross-checked by GPT-5.3-Codex and Claude Sonnet 4.5. Holistic AssessmentMotivation: Justified. This implements Approach: Correct and simpler. Each stream gets its own read loop ( Summary: ✅ LGTM. The refactoring is correct, simpler than what it replaces, and handles all buffer lifecycle edge cases properly. No blocking issues found. Two minor suggestions below. Detailed Findings✅ Buffer ownership — Correct across all code pathsVerified all paths through
✅ Exception handling — Correct for all scenarios
Note: Claude Sonnet 4.5 flagged a potential cancellation bug where both tasks being cancelled would throw ✅ Modern API usage — Good improvement
✅ Test coverage — AdequateThe new 💡
|
Description
Adds asynchronous
ReadAllTextAsync(CancellationToken)andReadAllBytesAsync(CancellationToken)APIs toSystem.Diagnostics.Process, enabling fully async multiplexed reads of both stdout and stderr.Implementation
ReadPipeToBufferAsync(Stream, CancellationToken)reads a single stream into a pooled buffer, owns the buffer lifecycle (returns to pool on failure viacatch, transfers ownership viaArraySegmenton success).ReadAllBytesIntoRentedArraysAsyncvalidates state, launches two parallelReadPipeToBufferAsynctasks viaTask.WhenAll, handles buffer cleanup for the successful task when the other fails, and surfaces both exceptions viaAggregateExceptionwhen both fail.GetSafeFileHandleFromStreamReaderinto OS-specificGetSafeHandleFromStreamReaderhelpers (Process.Multiplexing.Windows.cs,Process.Multiplexing.Unix.cs), usingSafePipeHandleon Unix andSafeFileHandleon Windows. Simplified syncReadAllText/ReadAllBytesto useAsSpan()directly.ProcessMultiplexingTestswithuseAsyncparameter across all existing test methods. Added cancellation test (ReadAllAsync_ThrowsOperationCanceledOnCancellation) and multi-exception test (ReadAllAsync_ThrowsAllAvailableExceptions).Testing