Skip to content
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

Provide more control over handle inheritance and standard in/out in System.Diagnostics.Process #24855

Closed
agocke opened this issue Jan 31, 2018 · 2 comments
Labels
area-System.Diagnostics.Process enhancement Product code improvement that does NOT require public API changes/additions
Milestone

Comments

@agocke
Copy link
Member

agocke commented Jan 31, 2018

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 to true. 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.

@stephentoub
Copy link
Member

In addition, System.Diagnostics.Process always creates processes with bInheritHandles set to true.

https://github.com/dotnet/corefx/issues/306

@wtgodbe
Copy link
Member

wtgodbe commented Feb 1, 2018

Closing as duplicate of https://github.com/dotnet/corefx/issues/306

@wtgodbe wtgodbe closed this as completed Feb 1, 2018
@msftgits msftgits transferred this issue from dotnet/corefx Jan 31, 2020
@msftgits msftgits added this to the 2.1.0 milestone Jan 31, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Diagnostics.Process enhancement Product code improvement that does NOT require public API changes/additions
Projects
None yet
Development

No branches or pull requests

4 participants