-
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
Console.Unix: reset terminal at exit in less cases to avoid blocking the parent. #42303
Conversation
…the parent. When a parent is fetching the Console.Cursor position, it configures the terminal to not echo, writes an escape sequence to query the position, and then reads the position from stdin. Because this doesn't happen atomically a child process can overwrite the terminal settings to echo before the parent starts reading. This causes the position to be echoed to the user, and the parent gets stuck waiting for input on stdin. Currently terminal settings are reset at exit for applications that use the Console or Process class. This change tracks whether the application has changes the terminal settings and only then resets the terminal settings. This doesn't fix the issue, but makes it less likely to occur.
I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label. |
I think we can't fix this fully because it would require the parent to prevent any child from changing the terminal settings while it is retrieving the cursor position. |
It sounds like we are stuck with this potential hang. That don’t seem ideal. Is this just an intrinsic flaw in how Unix consoles work? Or our API design? |
Because multiple operations are involved, it is not possible to retrieve the cursor position in a thread-safe way. So it's a Unix limitation. Since this is not a Windows limitations, .NET applications are not written to accommodate for it. They can by doing this:
|
@stephentoub, @danmosemsft can you merge this one? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @tmds.
When a parent is fetching the Console.Cursor position, it configures the terminal
to not echo, writes an escape sequence to query the position, and then reads the
position from stdin.
Because this doesn't happen atomically a child process can overwrite the terminal
settings to echo before the parent starts reading. This causes the position to
be echoed to the user, and the parent gets stuck waiting for input on stdin.
Currently terminal settings are reset at exit for applications that use the
Console or Process class. This change tracks whether the application has
changes the terminal settings and only then resets the terminal settings.
This doesn't fix the issue, but makes it less likely to occur.
Contributes to #42247.
@stephentoub @eiriktsarpalis ptal.