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

fix: panic on SIGHUP by closed /dev/tty #1303

Closed
wants to merge 1 commit into from

Conversation

ThomasFrans
Copy link
Contributor

This fixes a panic caused by the SIGHUP signal being sent to the process after its controlling terminal closes. Handling SIGHUP isn't necessary as we're not interested in whether the controlling terminal closed, only in the fact that we need to terminate. SIGTERM will always be sent as well so just react to that.

closes #1282

This fixes a panic caused by the `SIGHUP` signal being sent to the
process after its controlling terminal closes. Handling `SIGHUP` isn't
necessary as we're not interested in whether the controlling terminal
closed, only in the fact that we need to terminate. `SIGTERM` will
always be sent as well so just react to that.
@ThomasFrans
Copy link
Contributor Author

This was an interesting one to find. I created a minimal version using just cursive and signal-hook which revealed that a minimal version shows the same behavior of panicking after receiving SIGHUP. I then removed the SIGHUP from the signals to handle and noticed the process still received SIGTERM when the terminal closed. I guess the kernel always sends signals in a specific order and makes sure to send SIGTERM BEFORE /dev/tty is closed, and SIGHUP AFTER /dev/tty is closed. It's a small thing but I didn't know it worked like this. Interesting bug 😄

@hrkfdn
Copy link
Owner

hrkfdn commented Oct 8, 2023

Does this also happen with the async handling from #1304? I'm wondering if there's some race condition due to duplicate signal handling and whether the way signals are handled (Cursive event loop vs. async task) makes a difference. Would test this myself but can't at the moment, unfortunately.

@hrkfdn hrkfdn force-pushed the fix-panic-on-sighup branch from 1abf8c1 to ce37893 Compare October 8, 2023 10:53
@ThomasFrans
Copy link
Contributor Author

ThomasFrans commented Oct 8, 2023

You're right. I think the other PR solved the issue and this one isn't necessary. I don't fully understand what is different between the previous approach and the current one with an async task, but if it works it works I guess 😄

I just noticed that there is a bug in the current main branch because I mixed up these two PRs when I was working on them and one SIGHUP went missing in the handle_signals() function at src/application.rs:64,20.

@ThomasFrans ThomasFrans closed this Oct 8, 2023
@ThomasFrans ThomasFrans deleted the fix-panic-on-sighup branch January 27, 2024 21:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

dump with tmux
2 participants