You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Running fish in gdb results with: Thread 1 fish received signal SIGTTIN, Stopped (tty input). 0x00007ffff776e15d in read () from /lib/libpthread.so.0
From the glibc documentation on SIGTTIN:
A process cannot read from the user’s terminal while it is running as a background job. When any process in a background job tries to read from the terminal, all of the processes in the job are sent a SIGTTIN signal. The default action for this signal is to stop the process. For more information about how this interacts with the terminal driver, see Access to the Terminal.
I can't repro the crash but I can repro the hang. Attaching in the debugger, fish just gets SIGTTIN repeatedly. I wonder if this broken when fish stopped blocking signals (#3691).
EIO I/O error. This will happen for example when the process is in a background process group, tries to read from its controlling terminal, and either it is ignoring or blocking SIGTTIN or its process group is orphaned.
It may also occur when there is a low-level I/O error while reading from a disk or tape.
So, I've checked this a bit, and this is the issue as I understand it:
For certain cases, fish creates a "keepalive" process. This is used to prevent reuse of the foreground pgroup leader PID, which would grant that new process access to the terminal. (Which in itself is an edgecase's edgecase, but theoretically more sound, so okay)
However, the check for a keepalive process is this:
if (j->get_flag(JOB_CONTROL) && !exec_error) {
for (constprocess_ptr_t &p : j->processes) {
if (p->type != EXTERNAL && (!p->is_last_in_job || !p->is_first_in_job)) {
needs_keepalive = true;
break;
}
}
}
So, if the job contains any process that isn't "EXTERNAL" (e.g. a builtin) and that process isn't both the first and last in the job (which would itself mean the job has only one process), create a keepalive process.
This keepalive process then becomes the foreground pgroup leader via set_child_group(j, keepalive.pid).
But in this case - read is executed in the fish process, so the pgroup that reads isn't the foreground pgroup. So it gets SIGTTIN/EIO/whatever, and that presents as this issue.
As I understand it, the process that should be allowed to read() from the terminal here is the first in the pipe - the read. Which is fish itself. So we don't actually need set_child_group, and we don't actually need the keepalive process (since fish itself survives).
And the process that should be allowed to write() to the terminal should be the cat. However IIUC the cat is actually started later since we buffer the read output (I can't actually see a running cat process here), so we don't need to explicitly do anything more.
TBD is the actual conditions that a keepalive process is necessary.
And now I'm down the job control rabbit hole again...
Activity
JohnMH commentedon Nov 17, 2017
Sometimes this also closes the terminal emulator.
zanchey commentedon Nov 18, 2017
It sure does, even with 2.7b1 - in a subshell the terminal hangs, in it's own window the emulator just closes!
floam commentedon Nov 19, 2017
Doesn't happen here (macOS), for some reason.
gyroninja commentedon Nov 27, 2017
Running fish in gdb results with:
Thread 1 fish received signal SIGTTIN, Stopped (tty input). 0x00007ffff776e15d in read () from /lib/libpthread.so.0From the glibc documentation on SIGTTIN:
A process cannot read from the user’s terminal while it is running as a background job. When any process in a background job tries to read from the terminal, all of the processes in the job are sent a SIGTTIN signal. The default action for this signal is to stop the process. For more information about how this interacts with the terminal driver, see Access to the Terminal.ridiculousfish commentedon Nov 27, 2017
I can't repro the crash but I can repro the hang. Attaching in the debugger, fish just gets
SIGTTINrepeatedly. I wonder if this broken when fish stopped blocking signals (#3691).Asternitix commentedon Nov 29, 2017
I can repro the hang as well but the text in the terminal goes black but still works.
gyroninja commentedon Nov 29, 2017
I'm using xterm 330 and fish 2.7.0.
The terminal does not seem to be crashing, but rather closing due to an error:
https://github.com/joejulian/xterm/blob/master/ptydata.c#L213
Essentially, the read call is failing with a errno of EIO. From the man page:
faho commentedon Dec 26, 2017
So, I've checked this a bit, and this is the issue as I understand it:
For certain cases, fish creates a "keepalive" process. This is used to prevent reuse of the foreground pgroup leader PID, which would grant that new process access to the terminal. (Which in itself is an edgecase's edgecase, but theoretically more sound, so okay)
However, the check for a keepalive process is this:
So, if the job contains any process that isn't "EXTERNAL" (e.g. a builtin) and that process isn't both the first and last in the job (which would itself mean the job has only one process), create a keepalive process.
This keepalive process then becomes the foreground pgroup leader via
set_child_group(j, keepalive.pid).But in this case -
readis executed in the fish process, so the pgroup that reads isn't the foreground pgroup. So it gets SIGTTIN/EIO/whatever, and that presents as this issue.As I understand it, the process that should be allowed to
read()from the terminal here is the first in the pipe - theread. Which is fish itself. So we don't actually needset_child_group, and we don't actually need the keepalive process (since fish itself survives).And the process that should be allowed to
write()to the terminal should be thecat. However IIUC thecatis actually started later since we buffer thereadoutput (I can't actually see a runningcatprocess here), so we don't need to explicitly do anything more.TBD is the actual conditions that a keepalive process is necessary.
And now I'm down the job control rabbit hole again...
Don't start keepalive process if the first or last process is internal
mqudsi commentedon Feb 9, 2018
The minimal
read | cattest case appears to be fixed with the recent changes:But I'd have to try on a non-WSL machine too, for sure.
faho commentedon Feb 10, 2018
Definitely not fixed on Linux.
JohnMH commentedon Feb 11, 2018
@mqudsi I'd be willing to bet that's more due to some issue with signals on Windows.
mqudsi commentedon Mar 5, 2018
@JohnMH it was actually due to the extraneous
setpgidcalls. The changes introduced to fix #4778 cause WSL to similarly hang now.Acquire tty if interactive when running builtins
Acquire tty if interactive when running builtins