-
Notifications
You must be signed in to change notification settings - Fork 2.1k
less is suspended/backgrounded when using two pipes with grep #8699
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
Comments
Great find and amazing repro steps! I am sure it was tedious to reduce this, thank you for taking the time. This is definitely a bug in fish. I am pretty sure the sequence is:
The right fix here is to only call
won't trigger it because there's no fish functions running. |
This is a big cleanup to how tty transfer works. Recall that when job control is active, we transfer the tty to jobs via tcsetpgrp(). Previously, transferring was done "as needed" in continue_job. That is, if we are running a job, and the job wants the terminal and does not have it, we will transfer the tty at that point. This got pretty weird when running mixed pipelines. For example: cmd1 | func1 | cmd2 Here we would run `func1` before calling continue_job. Thus the tty would be transferred by the nested function invocation, and also restored by that invocation, potentially racing with tty manipulation from cmd1 or cmd2. In the new model, migrate the tty transfer responsibility outside of continue_job. The caller of continue_job is then responsible for setting up the tty. There's two places where this gets done: 1. In `exec_job`, where we run a job for the first time. 2. In `builtin_fg` where we continue a stopped job in the foreground. Fixes fish-shell#8699
This is a big cleanup to how tty transfer works. Recall that when job control is active, we transfer the tty to jobs via tcsetpgrp(). Previously, transferring was done "as needed" in continue_job. That is, if we are running a job, and the job wants the terminal and does not have it, we will transfer the tty at that point. This got pretty weird when running mixed pipelines. For example: cmd1 | func1 | cmd2 Here we would run `func1` before calling continue_job. Thus the tty would be transferred by the nested function invocation, and also restored by that invocation, potentially racing with tty manipulation from cmd1 or cmd2. In the new model, migrate the tty transfer responsibility outside of continue_job. The caller of continue_job is then responsible for setting up the tty. There's two places where this gets done: 1. In `exec_job`, where we run a job for the first time. 2. In `builtin_fg` where we continue a stopped job in the foreground. Fixes fish-shell#8699
I have a minor issue where
less
gets suspended/backgrounded unexpectedly when using two pipes and the last one is agrep
(with some caveats, see below). It's easy to work around, so not a big priority but I wanted to raise it if other people stumble upon it.How to reproduce the issue
I can reliably reproduce the issue both using
fish --no-config
andsh -c 'env HOME=$(mktemp -d) fish'
.Interestingly, replacing
cat minimal_example.txt
withstring repeat -n 50 \n
or replacinggrep '.*'
withcat
"fixes" the issue. Also the pipeline must have two pipes, e.g.grep '.*' minimal_example.txt | less
works perfectly fine.Furthermore, it seems related to terminal height. If I resize the terminal window to be tall enough for all the lines to fit the window the issue also does not occur.
The issue happens both when
fish
is run in Terminal.app and iTerm2. It does not occur inbash
andzsh
(not thatfish
should emulate any of those -- but this feels like bug).In this asciinema video of the issue, the issue only happens on the second invocation, so it might be some kind race-condition. I currently hit the bug 95% of the time I run the test command, but it's been a bit lower previously.
fish version
I'm on a Macbook Pro (Apple M1 Pro) with macOS 12.2.
The text was updated successfully, but these errors were encountered: