You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ext/pcntl (ZTS): a process-directed signal delivered to a non-PHP thread crashes in pcntl_signal_handler #25541
On a ZTS build configured with --disable-zend-signals (as Homebrew's php-zts is), pcntl_signal_handler() is installed directly with sigaction() and reads PCNTL_G(...) without checking that it is running on a PHP thread. (With zend signals enabled, zend_signal_handler_defer() already checks tsrm_is_managed_thread() before anything reaches pcntl.) A process-directed signal (kill(), alarm()) may be delivered to any thread that does not block it. On macOS, every PHP process has libdispatch worker threads. When the signal lands on one of those threads, the handler dereferences that thread's (absent) TSRM globals.
In a larger application, the same race shows up as zend_mm_heap corrupted (exit 134) or as a hash lookup that never ends (zend_hash_find spinning). Both appear when a single pcntl_alarm() handler fires while the main thread is busy.
The NTS build of the same version never crashes (0 of 6 runs; also 0 of 6 on an NTS debug build), which is consistent with NTS globals being process-wide.
A storm makes it likely because pcntl_signal_dispatch() blocks every signal on the main thread while it runs handlers, so the kernel has to pick another thread for a process-directed signal that arrives in that window.
A fix along the lines of zend_signal_handler_defer(): under ZTS, when !tsrm_is_managed_thread(), don't touch PCNTL_G(), and forward the signal with pthread_kill() to the thread that installed the handler. I have a PR for this, with a deterministic test that raises the signal on a raw pthread through a new zend_test helper.
PHP Version
PHP 8.5.12 (cli) (ZTS), Homebrew php-zts (NTS 8.5.11 for comparison)
Update after working on GH-25542. Some of the description above needs correcting:
Builds with zend signals are affected too. The description implies they are protected. They do not crash in pcntl_signal_handler(), but zend_signal_handler() falls back to the original disposition on a thread that never ran PHP. A signal with a pcntl handler therefore terminates the process. This is the default ZTS configuration.
GH-25542 now fixes this issue together with GH-25548 and GH-25549, which came out of the same investigation. Its description documents the signal policy and the remaining limitations.
Activity
phcorp commentedon Nov 18, 2026
Update after working on GH-25542. Some of the description above needs correcting:
pcntl_signal_handler(), butzend_signal_handler()falls back to the original disposition on a thread that never ran PHP. A signal with a pcntl handler therefore terminates the process. This is the default ZTS configuration.zend_mm_heap corruptedandzend_hash_findsymptoms in isolation, so I cannot say whether Fix GH-25541, GH-25548, GH-25549: forward signals from threads without PHP context #25542 fixes them.Two related problems are tracked separately: GH-25548 and GH-25549.
phcorp commentedon Nov 18, 2026
GH-25542 now fixes this issue together with GH-25548 and GH-25549, which came out of the same investigation. Its description documents the signal policy and the remaining limitations.