-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
external commands launched from a function may not be killed when fish receives a SIGHUP #3737
Comments
@Ambrevar: None of the functions shipped by this project include the statement that fish is complaining about; i.e., Please understand that I am not claiming the fish scripts on your system are broken. Fish should never report the errors you saw which implies a bug in fish. But understanding the conditions that trigger the problem is the first, and most important, step to fixing the problem. |
Googling |
Yes,
If I comment
Then I either get the same error message with
Pressing any key will close the terminal. If I comment Same thing if I reset my Command substitutions / jobs seem to have a role here. |
fzf just released version 0.16 (and 0.16.1) which does not require ncurses anymore, and thus does not trigger the issue. So let's focus on Let me repeat the requirements and steps:
And close the terminal or send SIGTERM to fish while I just found out that if you send SIGHUP to fish, you get the same behaviour as for xterm. So the difference between the 2 is that urxvt closes its children with SIGTERM while xterm does it with SIGHUP. |
Good news. I installed Ubuntu 16.10 which has glibc 2.24 and ncurses 6.0 (plus Ubuntu changes for both packages). I was able to reproduce the problem using @Ambrevar's instructions. I did not need urxvt. I simply ssh'd into the system, ran the function which invoked It shouldn't take much effort now to determine the root cause of this behavior. Which is not the same thing as saying a fix will be easy. |
Also, sending SIGTERM produces the problem where |
Also, it isn't necessary to invoke ncdu indirectly via a function. If I run |
Argh! The problem with SIGHUP is due to the change I recently introduced to warn the user about exiting when external commands are running. That warning, which also means not killing those child processes, should only be done when the shell is exiting for reasons other than having received a signal. If we're exiting because we received SIGHUP we should silently kill the child processes. |
I have a fix for the SIGHUP aspect of this problem. I'll merge it as soon as I've created a unit test to keep it from regressing in the future. Bash does not kill background tasks when it receives SIGTERM. So neither should fish. On the other hand it doesn't exit when interactive and it receives SIGTERM while running another program in the foreground. Whereas fish does exit which leaves the foreground process reparented to PID 1. That is wrong. |
Note that bash does exit when it receives SIGTERM when not interactive (e.g., |
This is a partial fix for issue #3737. It only addresses the SIGHUP aspect of the problem. Fixing SIGTERM is TBD.
I'm closing this because the core problem, SIGHUP handling, is fixed. Changing how SIGTERM is handled should be dealt with in a separate issue since the current behavior is quite old and upon further reflect it isn't obvious we should change it. |
Thanks for doing this! |
I'm not sure what we need to say in the release notes - has the behaviour here changed since 2.4.0? |
@ridiculousfish @krader1961 any guidance? |
@zanchey: I think the only thing needed is to mention that attempting to exit when jobs are in the background will now result in a warning and tell you to type |
Did we change the behavior of sending SIGHUPs to children on shell exit? |
Yes, issue #3155. This issue is in response to the warning introduced by issue #3497 and PR #3658. That change (and this fix) didn't change our sending of SIGHUP to child process but did change how fish reacts to receiving SIGHUP. |
Sorry, still trying to wrap my head around this...
Wasn't this the behavior already? What's changed here? |
The new behaviour is that running, as well as stopped jobs, will get terminated - this was noted in the 2.5b1 release notes. |
Ah, yes it is. When I glanced at them last night I didn't see that line item. I think we're good to go. |
Cool, thanks for the clarification |
This issue is derived from issue #3644. The core complaint is that programs like
ranger
andfzf
may not be killed if launched from a function if fish dies because it's controlling tty becomes invalid.Notably, @Ambrevar, reports that when he attempt to kill the xterm that fails with fish writing this to the terminal:
Note that @Ambrevar is doing
exec fish
from their ~/.bashrc rather than make fish their login shell. Recent PR #3658 might be relevant but note that change was made several days after issue #3644 was opened.One known problem that is thatshow_stacktrace()
cannot be used safely on the child side of afork()
. And we have at least one stack trace showing it being called in that situation (see the final comments on issue #3644). That should be fixed. That isn't going to be the root cause of this issue but is a contributing factor that at least makes it harder to debug.It turns out my previous paragraph was in error. The
show_stacktrace()
call in question was made in the parent process which should be okay. That appears to be another manifestation of the glibc stdio bug when the fd is returning EIO.The text was updated successfully, but these errors were encountered: