[php-src] PR #25974: ext/opcache: Defer signals while the JIT compiles
| From: | jorgsowa | Date: | Mon, 30 Nov 2026 20:58:26 +0000 |
| Subject: | [php-src] PR #25974: ext/opcache: Defer signals while the JIT compiles | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-41285@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/25974
Author: jorgsowa
JIT compiles store SSA and call graph data in the shared
func_info of the op_arrays
they touch, and clear it when the compile ends. If a signal kills the process mid-compile,
func_info keeps pointing into the dead process's arena. The next compile in
another process reuses it and crashes, or hits Assertion failed: info & (1 <<
type) in zend_jit_trace_type_to_info_ex().
This is the cause of the intermittent ext/pcntl/tests/001.phpt failure on
ALPINE_X64_ASAN_DEBUG_ZTS: a forked child gets SIGTERM while compiling a trace, and the parent
reuses its leftover SSA. In production, FPM's request_terminate_timeout sends the
same SIGTERM.
Fix:
- Wrap the five compile entry points (root trace, side trace, first-exec, hot counters, profiling at
request shutdown) in HANDLE_BLOCK_INTERRUPTIONS(). Opcache already does this around its
other SHM updates (ad55348e661). The JIT never did.
- Clean up func_info when a function compile bails out too. Every blocked section
unblocks before re-throwing the bailout (see 38f1288b642).
Concerns:
- SIGKILL and the OOM killer can't be deferred, so they can still leave stale data. That's
also true of every other opcache SHM update. Covering them requires wiping func_info on
the next compile. I have that version, but it's more invasive than a fix for 8.4 should be.
- A SIGTERM or SIGINT that arrives during a compile is delivered when the compile finishes. Compiles
are short, and opcache already defers them the same way while persisting a script.
- No effect on Windows or on --disable-zend-signals builds, where the macros compile to
nothing.
- There's no test for the bailout cleanup. I couldn't get a reliable mid-compile
memory-limit bailout, and Zend MM hides the stale reads.
The tests fork a child and set opcache.jit_debug=2 in it, so it blocks writing the SSA
dump to a socket in the middle of a compile. The parent sends SIGTERM, then runs code that would
reuse the leftover data. All five tests crash under ASan without the fix.
Merging up: applies cleanly to PHP-8.5. On master there's a trivial conflict,
0/1 vs false/true in the
zend_jit_check_funcs() calls.
The flaky test is the first attempt of ALPINE_X64_ASAN_DEBUG_ZTS on PR #25946, which failed: https://github.com/php/php-src/actions/runs/46443912300/job/141936152537
The re-run passed: https://github.com/php/php-src/actions/runs/46443912300/job/141988272688