Repository navigation
Conversation
…ls the process Under ZTS, a process signal can be delivered to a thread that has no TSRM storage, e.g. a Go runtime thread in FrankenPHP or any thread an embedder creates. pcntl_signal_handler() then read PCNTL_G() through a NULL pointer (--disable-zend-signals), and zend_signal_handler_defer() fell back to the original disposition, so SIG_DFL killed the process although the script registered a handler. On such a thread, for a signal PHP handles, add the signal to the mask saved in the interrupted context and send it to the process again. The kernel delivers it to a thread that does not block it, which converges on a PHP thread. Threads unblock re-routed signals when they start a request. Faults and abort() keep their default action on the thread they hit. Re-routing is enabled on Linux, macOS and FreeBSD, where it was verified.
phcorp
requested review from
devnexen,
dstogov and
kocsismate
as code owners
November 19, 2026 08:12
This was referenced Nov 19, 2026
A signal whose handler was set back to SIG_DFL kept being sent on from a thread that never ran PHP. If every PHP thread blocked it, the signal stayed pending instead of taking its default action. Count the PHP threads whose handler is neither SIG_DFL nor SIG_IGN, and only re-route while that count is positive. The count follows every write to a thread's handlers and drops when a thread's storage is freed. zend_test_start_foreign_thread() starts a thread that never runs PHP and stays alive, so a test can block the signal on the PHP thread only.
…lost Under ZTS without zend signals, the process-wide execution timer can fire on a thread that has no TSRM storage. zend_timeout_handler() printed a message and returned, and as it was installed with SA_RESETHAND, the next signal killed the process. Install the handler with SA_SIGINFO and without SA_RESETHAND under ZTS, and re-route the signal from such a thread to the PHP threads, as phpGH-25541 does for pcntl. With zend signals, the timeout handler is already re-routed. A PHP thread that has no timeout armed ignores the signal: it is stale (the timer was disarmed) or belongs to another thread's timer.
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.
Depends on #25580 (GH-25541); only the last commit is new.
Under ZTS where the execution timer is process-wide (
setitimer(): macOS, FreeBSD, not Linux, which uses per-thread timers), the timer signal can fire on a thread that never ran PHP. Without zend signals,zend_timeout_handler()prints "called in a thread not managed by PHP" and returns, so the timeout is lost. Because it was installed withSA_RESETHAND, the next signal kills the process.Reproducer (ZTS,
--disable-zend-signals, macOS arm64):set_time_limit(30); zend_test_raise_on_foreign_thread(SIGALRM); while (true);. The timeout is lost, and the next timer signal kills the process instead of "Maximum execution time of 30 seconds exceeded" being reported.Fix: under ZTS, install the timeout handler with
SA_SIGINFOand withoutSA_RESETHAND. On a thread without TSRM, re-route the signal with the helper from GH-25541; with zend signals, that already happens. A PHP thread that has no timeout armed now ignores the timer signal. Before this, a stale signal arriving afterset_time_limit(0)reported "Maximum execution time of 0 seconds exceeded". This replaces the 2-second window from #25542.Not covered:
setitimer()gives the process one timer, so with several PHP threads the lastset_time_limit()wins, and the signal may reach a PHP thread other than the one that armed it. That thread ignores it if it has no timeout of its own, so the other thread's timeout is lost. This is the same as today; only per-thread timers (ZEND_MAX_EXECUTION_TIMERS, Linux only) fix it.Questions for reviewers: