-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Breaking Change Request: Don't restore terminal state on exit #45630
Comments
fyi @jonahwilliams |
Also fyi @zanderso We already have the existing hooks to be able to restore terminal state on exit, so the required tool change should be fairly minor. My understanding is that if we get sigkilled we don't get a chance to run these, but then neither does the existing VM code? As long as we don't regress this behavior I don't imagine there would be any problems. |
I can't remember if we discussed this, but is there a reason An example where this is horrible is on zsh, which is now the default shell on macOS. Running Running |
Thanks @zanderso and @cbracken for that valuable context about the #30318 bug. A solution is required in order to prevent this bug from returning if this breaking change is made. I propose we amend this breaking change proposal with making Does that resolve your concerns? I have implemented this proposed behavior in https://dart-review.googlesource.com/c/sdk/+/190484. |
I don't think the reason is documented anywhere, and my memory is imperfect, but it was probably a combo of:
On (3), I'm still a little skeptical of this change. It adds the requirement that any program that modifies the echo modes must record them before modifying them, and install signal handlers and on-exit handlers to restore them to their previous state. I suspect that there aren't many command line programs that currently have that. The But I guess this is a breaking change proposal, so the mitigation would be updating the documentation for |
@sortie Do you think this is at the stage for the final approval? |
This shouldn't have an impact on AngularDart nor do I see the need for it. |
@sortie - is this something we're still pushing on? |
I think this is still worth landing. @sortie do you have cycles to see this through? |
I have updated https://dart-review.googlesource.com/c/sdk/+/190484 so it can land once this breaking change request is approved. |
Any updates on this from the review meetings? Any objections to fixing currently broken behavior? |
This change should be ready to roll out now if approved. It may cause some subtle breakage in some tooling that messes with the terminal settings and expects it to be restored, although I found very few cases when I tried looking last time. It'll probably be easier to find and fix these cases by landing this change, and either doing small fixes to those cases or reverting the change while the fixes are being made. |
Before landing, please test using the |
I don't see any adverse effects on flutter tools being killed neither on Windows or on Linux with proposed patch applied: the console shell/window that used to launch flutter tools seems to continue normally after flutter tools is killed. |
Nice. Another test case might be the usecase that caused me to file the original issue. Running with |
terminating running |
@itsjustkevin is there more information needed to make a decision on this? |
LGTM from an AngularDart perspective. |
SGTM |
SGTM. |
@a-siva @brianquinlan - you ok with the Otherwise, LGTM |
The changelist has been reviewed and was waiting for this breaking change approval before it could land. |
lgtm |
Team, marking this breaking change as approved. |
thank you all, will submit https://dart-review.googlesource.com/c/sdk/+/190484 shortly |
Proposal
We propose to make the Dart VM stop automatically restoring the terminal settings upon exit. A proposed implementation is at https://dart-review.googlesource.com/c/sdk/+/190484.
Programs that set
Stdin.echoMode
orStdin.lineMode
must now manually restore the terminal settings upon exit if they wish.Rationale
The automatic terminal setting restoration happens unconditionally and can lead to undesirable behavior e.g. when the program does not care about terminal settings and is sharing a process group with a program that does care. E.g. if dart's output is piped into less(1), then there is a race condition where dart might see the raw terminal settings set by less(1), and if the dart VM exits after less(1) has exited, then it will restore the raw terminal settings, leaving the user with a seemingly defective shell with echo disabled. This race condition can be reproduced using:
The user will end up with a shell with echo behavior disabled. The stty command shows the current terminal settings, where the difference can be seen, and stty sane fixes the settings before returning to the shell prompt. The stty sane call can be omitted to see the defective shell prompt.
dart:io
already provides all the functionality for programs to correctly implement the restoration behavior themselves. This class of terminal setting corruption bugs are eliminated by shifting the burden onto the programs that use interactive input and change these settings. This design matches that of other programming languages.Impact
Affected programs won't break for the duration of their run, although the terminal state settings for line mode and echo mode may be unexpected afterwards, especially if the program is terminated by a signal or an unhandled exception. Users of POSIX systems can manually repair their terminal session by running
stty echo echonl icanon
orstty sane
.Mitigation
Programs that change the
Stdin
settingslineMode
andechoMode
are now responsible for restoring the settings upon program exit. E.g. a program disablingechoMode
will now need to restore the setting itself and handle exiting by the appropriate signals if desired:The text was updated successfully, but these errors were encountered: