Repository navigation
fix: don't kill grandchildren of forked processes - #2703
Merged
Merged
Conversation
The atfork child handler ties each forked child to its parent's lifetime. atfork handlers survive fork, so a child that forks again without exec'ing tied the grandchild to the short-lived intermediate process. Double-forking code such as gpgme (used by the gnupg extension to run gpgconf) had its grandchild killed as soon as the intermediate exited. Only protect direct children of the FrankenPHP process. Fixes #2689
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2689, a regression since 1.12.5.
#2390 added a
pthread_atforkchild handler that ties each forked child to its parent's lifetime:PR_SET_PDEATHSIGon Linux,procctlon FreeBSD, a kqueue watcher on macOS and the other BSDs.Fork handlers survive
fork(); onlyexec()clears them. When a forked child forks again without exec'ing, the handler runs again and ties the grandchild to the short-lived intermediate process. gpgme (used by the gnupg extension) double-forks to startgpgconf, so the grandchild is killed as soon as the intermediate exits, and gnupg fails with "could not init keylist".The handler now returns early in a process that is already a forked child. Only direct children of FrankenPHP get the protection. Grandchildren still inherit
is_forked_child, so the SAPI output guards still apply.The new test forks twice from PHP. It needs pcntl and skips without it. With pcntl loaded, it fails on
main(grandchild-killed) and passes with the fix.