-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
process: block SIGCHLD signal when spawning process #6953
base: master
Are you sure you want to change the base?
Conversation
@ipetkov what do you think? At the very least, this code looks like it would break if called in parallel from two threads at once. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't this cause child processes that complete while SIGCHLD
is blocked to hang?
Very much agree with this statement; this proposed change does not look safe in the general sense. Even if we were to introduce our own mutex here there's no guarantee that some other part of the process isn't trying to mess with signals. I have two main questions:
|
Thank you for reviewing! Here is a bit more context in case it's useful. Steps to reproduce the issue:
(sorry I don't have a shorter way to reproduce!) In order to test the fix in this PR, compile Jujutsu against custom version of Tokio
Not 100% sure.
I observed that the I did try installing signal before the spawn call - didn't help. IIRC installing signal handler is not guaranteed to have immediate effect (cannot find a reference at the moment).
Pending signals are delivered after unblocking (https://man7.org/linux/man-pages/man7/signal.7.html).
Signal is blocked for all threads but unblocking it by one thread could affect concurrent calls to Playing with signals in a library is inherently fragile - it's unfortunate that macOS version is relying on signals IMHO. Linux implementation is using file descriptors. |
I'd recommend running the test scenario under |
Motivation
I'm observing that waiting for
tokio::process::Command
occasionally hangs on macOS (reproduced in Jujutsu version control CLI executed from inside jj_tui). Issue #6770 looks similar.Solution
Inspecting the code, there seems to be a race possible between registering signal handler for SIGCHLD and receiving signal. Standard solution is to block signal during forking: https://stackoverflow.com/a/6757240. This is implemented in the pull request.
With this change I cannot reproduce hanging anymore.