-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Quit child processes when supervisor crashes (Linux only) #199
Conversation
Use prctl(PR_SET_PDEATHSIG, SIGTERM) to send signal when parent dies
+1! |
This fix would be very useful. |
Seen this happen once in our staging setup. This is worth the fix. |
+1 Thought maybe only running the code when you're on linux might be better than just catching the exception and also added a constant. Happy if you want to merge the change into this PR. https://github.com/lukeweber/supervisor/tree/zombie-process-fix |
#649 is an alternative version of this pull request that adds a check. |
And I added a constant PR_SET_PDEATHSIG with a comment about where it came from in case anyone's unsure about what 1 does. Also no conflicts to merge. This pull has been open for a long time. |
Thanks for the pull request @srwilson and @lukeweber. First, if you guys have seen About If There's not another case in I do agree with a change in @lukeweber's PR, if we know this is a Linux-only thing, we should only attempt it on Linux. Also, most config settings will raise |
I run supervisor as a component in a PaaS (https://bitbucket.org/yougov/velociraptor/) where application instances are typically redundant and load balanced anyway. We can easily tolerate Supervisor dying and taking all its processes with it, but if it dies and leaves zombies behind, that's quite a mess to clean up. +1 to the PR. A Linux-specific config would be fine. |
I don't think I had a specific crash but was playing with things when I was figuring out my code deployment. Was using unicornherder in supervisor 3.0 and this is what I ran into.
So I've verified besides extra unicornherder processes this isn't really a problem I think because either process does communicate with the workers, but initially I was concerned that I might be sending my signal to the wrong pid because I rely on this to update code(supervisorctl -c $SUPERVISOR_CONF pid $APP_NAME | xargs kill -s HUP) and if it wasn't talking to the right workers it would silently fail. @mnaberez - I'm not an expert on the process logic, but could you confirm: Even though things are reparented, they aren't managed as the old running process and a new process is launched when supervisord starts? I think it's a question of whether you want the possibilities of zombies or multiple processes running, which is sometimes even worse than nothing, but agree it's probably best as a judgement call leaving the default as is. I'm thinking of things that might not be safe to run two of here or might be strictly undesirable. |
If Not quite related to this ticket, however: an orphaned process situation like you described can happen even if
Yeah, if we add support for |
I've updated my pull request to be a config option that can only be set on linux and I added tests for the config. |
* Original pull inspired by: Supervisor#199 * If the supervisor process dies, that the child process will receive this signal set in prsetpdeathsig.
If supervisor crashes, its child processes left running and inherited by supervisor's parent process. I've added a way to send these processes a stop signal if the parent goes away using prctl(PR_SET_PDEATHSIG, SIGTERM). It only works on Linux. On other platforms exceptions are caught and ignored.
I've not run it on anything besides Linux yet.
To test it, start supervisor then send it a kill -9. The child process receives the SIGTERM as expected.