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

otp 26 messes up the tty #8487

Closed
mbj4668 opened this issue May 16, 2024 · 2 comments · Fixed by #8794
Closed

otp 26 messes up the tty #8487

mbj4668 opened this issue May 16, 2024 · 2 comments · Fixed by #8794
Assignees
Labels
bug Issue is reported as a bug team:VM Assigned to OTP team VM
Milestone

Comments

@mbj4668
Copy link

mbj4668 commented May 16, 2024

Describe the bug
Run an escript that prodcues (slow) output, pipe it to less, and hit q to quit less. The tty is now in a bad state (e.g., with bash, prev history doesn't work). reset or stty sane is needed to fix it.

To Reproduce
Save the script below as test, make it executable and run test <name of a large text file> | less in bash. Hit q. Wait. When you get the bash prompt, try ctrl-p etc.

#!/usr/bin/env escript
%% -*- erlang -*-

main([FName]) ->
    {ok, Fd} = file:open(FName, [read]),
    loop(Fd),
    file:close(Fd).

loop(Fd) ->
    case file:read(Fd, 1024) of
        {ok, Data} ->
            io:put_chars(Data),
            timer:sleep(500),
            loop(Fd);
        _ ->
            done
    end.

Expected behavior
The tty should not be messed up. Also, it takes several seconds more than in 25 to get the prompt back.

Affected versions
I have tried 26.1.2 and 26.2.5.

@mbj4668 mbj4668 added the bug Issue is reported as a bug label May 16, 2024
@IngelaAndin IngelaAndin added the team:VM Assigned to OTP team VM label May 20, 2024
@garazdawi
Copy link
Contributor

I dug into this and what happens is that when we try to be clever and restore the tty settings after the exit of Erlang we restore them to the values set by less... I'll see if I can add some bandaid, but it would seem like no matter what we do the shell will end up broken in some scenario.

garazdawi added a commit to garazdawi/otp that referenced this issue Sep 9, 2024
If stdout is not a tty, then it might be a program that does its own
alterations of the tty which means that we should not touch it and
leave restoration to that program.

Closes erlang#8487
@garazdawi garazdawi linked a pull request Sep 9, 2024 that will close this issue
@garazdawi garazdawi added this to the OTP-27.2 milestone Sep 19, 2024
@garazdawi
Copy link
Contributor

Fix merged to be part of 27.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue is reported as a bug team:VM Assigned to OTP team VM
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants