chore: fix gRPC fork deadlock in Ubuntu unit tests - #9633
Closed
bshaffer wants to merge 1 commit into
Closed
Conversation
When the PHP gRPC extension is loaded, calling pcntl_fork() and exiting in the child causes a futex deadlock in gRPC C-core due to unreleased locks / missing background threads in the child process. Enabling GRPC_ENABLE_FORK_SUPPORT=1 registers gRPC's pthread_atfork handlers, allowing child processes to exit cleanly. Also adds a skip guard to RaceConditionTest if gRPC is loaded without fork support enabled.
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.
Description
This PR fixes the issue causing the Unit tests in Ubuntu (and Package tests) on PR #9514 to hang and time out after 6 hours.
Root Cause
Auth/tests/Cache/RaceConditionTest.phpusespcntl_fork()to test concurrency across 4 child processes.grpcextension is installed for Ubuntu runners.grpcC-core extension is loaded in a PHP process, background threads and mutexes are initialized. Whenpcntl_fork()is called, POSIXfork()only clones the calling thread, leaving unreleased locks and absent background worker threads in the child process.exit(0), PHP runs module shutdown, which deadlocks indefinitely on a futex (futex_do_wait) waiting on mutexes/threads that do not exist in the child.pcntl_waitpid(), and PHPUnit is stuck waiting for the test process to finish, causing the 6-hour timeout in CI.run-package-tests.shbecauseAuthis included in the package test directory loop and run under xargs.pcntl_forkis unsupported on Windows (test was skipped), and passed onPHP 8.1 Unit Test (no gRPC)becausegrpcwas not installed.Solution
GRPC_ENABLE_FORK_SUPPORT=1tounit-tests.yaml,run-package-tests.sh,phpunit.xml.dist, andAuth/phpunit.xml.dist. This enables gRPC'spthread_atforkhandlers to properly reset C-core state post-fork so child processes exit cleanly.Auth/tests/Cache/RaceConditionTest.phpso that if a developer runs PHPUnit locally withgrpcloaded and withoutGRPC_ENABLE_FORK_SUPPORT=1, the test skips with an informative message instead of hanging.