-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Don't dup stdin & stderr as this can break some std io redicection code #25394
Comments
Why do we have to dup the stdin/out/err ? Comment would be nice. |
That dup comes from this commit from several years ago: The commit includes the comment: I'd need to look in a bit more depth, but presumably the issue is we don't want the streams returned by Console.OpenStandardInput/Output/etc. to close these fds. There are other ways to avoid that, though (e.g. telling the SafeHandle it doesn't own the fd); don't know for sure that's the issue, nor whether such a change would break other things. |
As a quick test, I've changed the code here https://github.com/dotnet/corefx/blob/master/src/System.Console/src/System/ConsolePal.Unix.cs#L25 to not dup the handle (for out and err), but I'm still seeing duplicated stdin, stderr handles. There must be another location where the handles are being duped. |
The Windows implementation is not closing the handle: runtime/src/libraries/System.Console/src/System/ConsolePal.Windows.cs Lines 1110 to 1119 in 4ae0dea
|
From @TheLastRar on March 10, 2018 13:8
Consider a program that does the follow;
Create pipes and dup2 the write fd onto stdin, stderr,
Have a thread continually read the pipes until EOF is reached (at which point the thread will terminate).
Use coreclr.
...
Restore the original stdin, stderr,
Close the write fd of pipes,
Wait for the pipe reader thread to terminate.
As coreclr dups the fd for stdin & stderr, there is still a write fd for the pipe, meaning the read thread will never receive an EOF and the program to hang at the last step.
Copied from original issue: dotnet/coreclr#16880
The text was updated successfully, but these errors were encountered: