From 7092365546fe4d64b1a1f979d34298c9a4b802a5 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Wed, 2 Sep 2026 20:41:01 +0000 Subject: [PATCH] chore: fix gRPC fork deadlock in unit tests by enabling fork support 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. --- .github/run-package-tests.sh | 1 + .github/workflows/unit-tests.yaml | 4 ++++ Auth/phpunit.xml.dist | 3 +++ Auth/tests/Cache/RaceConditionTest.php | 5 +++++ phpunit.xml.dist | 1 + 5 files changed, 14 insertions(+) diff --git a/.github/run-package-tests.sh b/.github/run-package-tests.sh index 489ce26317cd..e868e242d9ea 100644 --- a/.github/run-package-tests.sh +++ b/.github/run-package-tests.sh @@ -156,6 +156,7 @@ export -f run_package_test_parallel export STRICT export PREFER_LOWEST export FAILED_FILE +export GRPC_ENABLE_FORK_SUPPORT=1 # Determine optimal parallelism: default to the number of CPU cores on the host runner MAX_JOBS=${MAX_JOBS:-$(nproc 2>/dev/null || echo 8)} diff --git a/.github/workflows/unit-tests.yaml b/.github/workflows/unit-tests.yaml index fa11eefebc69..3fa419126f44 100644 --- a/.github/workflows/unit-tests.yaml +++ b/.github/workflows/unit-tests.yaml @@ -7,6 +7,10 @@ on: permissions: contents: read + +env: + GRPC_ENABLE_FORK_SUPPORT: 1 + jobs: test: strategy: diff --git a/Auth/phpunit.xml.dist b/Auth/phpunit.xml.dist index 2e2253269177..127b65307ed6 100644 --- a/Auth/phpunit.xml.dist +++ b/Auth/phpunit.xml.dist @@ -13,4 +13,7 @@ tests + + + diff --git a/Auth/tests/Cache/RaceConditionTest.php b/Auth/tests/Cache/RaceConditionTest.php index 34d8b4249fea..63a7463c6ff7 100644 --- a/Auth/tests/Cache/RaceConditionTest.php +++ b/Auth/tests/Cache/RaceConditionTest.php @@ -45,6 +45,11 @@ public function testRaceCondition(string $cacheClass) if (!function_exists('pcntl_fork')) { $this->markTestSkipped('pcntl_fork is not available'); } + if (extension_loaded('grpc') && !getenv('GRPC_ENABLE_FORK_SUPPORT')) { + $this->markTestSkipped( + 'Cannot run fork test with grpc extension unless GRPC_ENABLE_FORK_SUPPORT=1 is set.' + ); + } for ($i = 0; $i < 50; $i++) { // SysV Cache warmup to prevent segment creation race if ($cacheClass === SysVCacheItemPool::class) { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index f94c12e3fbb3..486f85902371 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -30,6 +30,7 @@ +