-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Open
Labels
api-suggestionEarly API idea and discussion, it is NOT ready for implementationEarly API idea and discussion, it is NOT ready for implementationarea-System.Diagnostics.Processcode-analyzerMarks an issue that suggests a Roslyn analyzerMarks an issue that suggests a Roslyn analyzerneeds-further-triageIssue has been initially triaged, but needs deeper consideration or reconsiderationIssue has been initially triaged, but needs deeper consideration or reconsideration
Milestone
Description
Background and motivation
I was investigating System.Diagnostics.Process issues today, and found out along the way some common patterns that can easily lead to deadlocks.
- Calling
process.[StandardOutput|StandardError].ReadToEnd()(or awaiting the async variant) after waiting for process exit. This can lead to deadlock if the child process attempts to write to stdout/stderr more than 4kb (the current buffer size). The child process will only be able to write the first 4kb of data, then it cannot write more data unless the written data is consumed by the parent process. But the parent process is waiting for process exit first before consuming the stream. So this will cause a deadlock. - Even with the order swapped, deadlocks can happen when both StdOut and StdErr are waited on sequentially.
API Proposal
Analyzer the warns when such patterns are detected.
API Usage
Example violations from real-world repos today:
https://github.com/dotnet/aspire/blob/05226437076bb5755e8a382a65bf027bc80e616c/src/Aspire.Cli/DotNet/DotNetSdkInstaller.cs#L47-L62 (I assume because stderr is redirected and is never read, this can deadlock if more than 4kb are attempted to be written to stderr.
Alternative Designs
No response
Risks
No response
Evangelink, martincostello, ImoutoChan and cfbao
Metadata
Metadata
Assignees
Labels
api-suggestionEarly API idea and discussion, it is NOT ready for implementationEarly API idea and discussion, it is NOT ready for implementationarea-System.Diagnostics.Processcode-analyzerMarks an issue that suggests a Roslyn analyzerMarks an issue that suggests a Roslyn analyzerneeds-further-triageIssue has been initially triaged, but needs deeper consideration or reconsiderationIssue has been initially triaged, but needs deeper consideration or reconsideration