[php-src] PR #25581: Fix GH-25548: Execution timeout on a thread that never ran PHP is lost
| From: | phcorp | Date: | Thu, 19 Nov 2026 08:12:48 +0000 |
| Subject: | [php-src] PR #25581: Fix GH-25548: Execution timeout on a thread that never ran PHP is lost | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-40802@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/25581
Author: phcorp
Depends on #25580 (GH-25541); only the second 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 with
SA_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_SIGINFO and without
SA_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 after set_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
last set_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:
1. When a PHP thread without a timeout gets the signal, is ignoring it right, or would you prefer a
hard error?
2. Should this go to 8.4, or only to master?