Provide more control over handle inheritance and standard in/out in System.Diagnostics.Process #24855
Labels
area-System.Diagnostics.Process
enhancement
Product code improvement that does NOT require public API changes/additions
Milestone
Right now it's impossible to pass your own handles (or set null handles) for a new process created with System.Diagnostics.Process. In addition, System.Diagnostics.Process always creates processes with
bInheritHandles
set totrue
. This has lead to complicated deadlocks for us in the past, where a process inherits the stdout of its parent, but the created process is a daemon, intending to live longer than its creator. If there is a third process that is the parent of the second which blocks waiting on standard output or the handle closing, this produces a deadlock because the daemon process will never close standard out or necessarily output anything on it.We currently work around this by either setting our own stdin/stdout/stderr, or by P/Invoking, but it would be nice to have a first-class API option here.
You can see here how Roslyn has worked around this issue in our compiler server by PInvoking, and how we work around the issue on Unix by creating dummy stdin/out/error to avoid inheriting the parent's.
The workaround is rather undesirable since, if we do end up accidentally outputting anything to standard out, there's a possibility that we may fill up the output buffer and never read from it, causing a different deadlock.
The text was updated successfully, but these errors were encountered: