-
Notifications
You must be signed in to change notification settings - Fork 3k
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
ERL-282: escript fails when redirecting stdout to less and less terminates #3150
Comments
|
|
|
|
|
|
|
I want to put down some of the reasons why I think that the issues linked above are duplicates of this. In OTP-18 I introduced this commit that sets the stdin and stdout fds to NONBLOCKING on unix. The reason why this change was done is described in the commit message:
As it turns out, this change comes with a host of issues for programs using the stdin/stdout fds of Erlang.
A partial solution to this problem could be to call So the solution for this in my mind is to remove the NONBLOCKING behaviour from the The best solution that I can come up with is to put all writes on dirty I/O schedulers, however, that would mean that we need to rewrite the ttsl driver to use nifs and that is a lot of work. Also the So right now I'm leaning towards creating two driver threads inside each ttysl/fd port that deals with the problems of reading/writing to blocking fds. This seems to be the solution with the least amount of work that we know will work. Unless anyone else has any better ideas? |
I don't think making the file descriptor nonblocking is the issue for "tty output after interrupting with +Bd/killing any shell is hosed," rather it's the tty modes set in ttsl_sdrv.c's I don't actually think setting a TTY FD to nonblocking mode changes behavior for other processes that have the same TTY open. (It will, of course, affect processes we fork off, but that doesn't seem to be a major concern for anyone.) Edit: I'm wrong about that, demonstration in https://gist.github.com/jktomer/8361b042236a5abbbafc1ce9836f22e1 |
Do I understand correctly that the discussion is about this line: https://github.com/erlang/otp/blob/master/erts/emulator/drivers/unix/ttsl_drv.c#L334 I tried removing it, and it seems to make no difference, |
Setting the tty file descriptor to nonblocking is not the cause of garbled terminal output. The issue is the tcsetattr call in tty_set, specifically the fact that it is normally called with the OPOST bit cleared as set up in tty_init. The comment above helpfully notes that setting raw mode on the terminal is OK "assuming the caller will call the tty_reset() function (also in this file) when it's done with raw mode." Setting the fd to nonblocking may cause other issues with pipelines. |
What shell and OS versions are you using to trigger the error with a garbled terminal? Also what exactly are you doing to trigger it? |
I think this issue is actually two issues merged. Might be useful to split it. Garbled terminal can be consistently reproduced with Mac OS X 11.2.2 and zsh (interestingly, bash seems unaffected). Running SET_NONBLOCKING I think causes a different issue (crash dumps when piping BEAM output to less/head/...) |
So that is why I haven't seen it. I'm still using bash on OS X and I very rarely run using |
All escripts (e.g. rebar3) are running with |
If it helps, I also have this issue. I'm on:
I do By garbled I mean stuff like
|
On Tue, Mar 9, 2021 at 3:16 PM Maxim Fedorov ***@***.***> wrote:
I think this issue is actually two issues merged. Might be useful to split
it.
Garbled terminal can be consistently reproduced with Mac OS X 11.2.2 and
zsh (interestingly, bash seems unaffected).
That's because bash explicitly resets the tty attributes whenever a child
program exits and the OS notes that it was terminated with a signal. Which
is actually a pretty clever feature and maybe I should upstream it to
zsh...
|
This commit re-implements the entire tty driver for both Unix and Windows to use a common nif instead of two seperate drivers. The Unix implementation works pretty much as it did before only that a lot more of the terminal logic has been moved from Erlang to C. The windows implementation now uses Windows Terminal Sequences, i.e. the same sequences as most Unixes to control the terminal. This means that werl.exe is no longer needed and erl.exe will have the "newshell" with all the features normally only found on Unix. The new implementation also uses dirty I/O threads for all I/O which means that it can leave the FDs in blocking mode. This fixes problems when the Erlang tty is interacting with other systems such as bash. Closes erlang#3150 Closes erlang#3390 Closes erlang#4343
If the cleanup code in sys_tty_reset is never run it can leave the terminal in a broken state. The cleanup code is not executed if erts receives a SIGKILL or if Ctrl-C is pressed when +B is started. Closes erlang#3150
This commit re-implements the entire tty driver for both Unix and Windows to use a common nif instead of two seperate drivers. The Unix implementation works pretty much as it did before only that a lot more of the terminal logic has been moved from Erlang to C. The windows implementation now uses Windows Terminal Sequences, i.e. the same sequences as most Unixes to control the terminal. This means that werl.exe is no longer needed and erl.exe will have the "newshell" with all the features normally only found on Unix. The new implementation also uses dirty I/O threads for all I/O which means that it can leave the FDs in blocking mode. This fixes problems when the Erlang tty is interacting with other systems such as bash. Closes erlang#3150 Closes erlang#3390 Closes erlang#4343
If the cleanup code in sys_tty_reset is never run it can leave the terminal in a broken state. The cleanup code is not executed if erts receives a SIGKILL or if Ctrl-C is pressed when +B is started. Closes erlang#3150
This commit re-implements the entire tty driver for both Unix and Windows to use a common nif instead of two seperate drivers. The Unix implementation works pretty much as it did before only that a lot more of the terminal logic has been moved from Erlang to C. The windows implementation now uses Windows Terminal Sequences, i.e. the same sequences as most Unixes to control the terminal. This means that werl.exe is no longer needed and erl.exe will have the "newshell" with all the features normally only found on Unix. The new implementation also uses dirty I/O threads for all I/O which means that it can leave the FDs in blocking mode. This fixes problems when the Erlang tty is interacting with other systems such as bash. Closes erlang#3150 Closes erlang#3390 Closes erlang#4343
If the cleanup code in sys_tty_reset is never run it can leave the terminal in a broken state. The cleanup code is not executed if erts receives a SIGKILL or if Ctrl-C is pressed when +B is started. Closes erlang#3150
If the cleanup code in sys_tty_reset is never run it can leave the terminal in a broken state. The cleanup code is not executed if erts receives a SIGKILL or if Ctrl-C is pressed when +B is started. Closes erlang#3150
Original reporter:
jj1bdx
Affected version:
OTP-19.1
Component:
erts
Migrated from: https://bugs.erlang.org/browse/ERL-282
The text was updated successfully, but these errors were encountered: