php-src icon indicating copy to clipboard operation
php-src copied to clipboard

Tracing JIT: intermittent segfault in JIT buffer in long-running CLI command (PHP 8.5.12, opcache.jit=tracing)

Open phuongvmhut opened this issue 1 week ago • 2 comments

Description

A Laravel scheduled CLI command (php artisan schedule:run, run every minute by cron) intermittently segfaults inside JIT-generated code.

It happens in bursts: once it starts, nearly every hourly run of the same scheduled workload crashes for 1–2 days (36 crashes on one day, 21 the next), then it stops on its own after unrelated code/data changes and does not recur for days.

Kernel log at the time of a crash:

php[3844339]: segfault at 0 ip 00005648b9e003eb sp 00007ffcd6eb38b0 error 4 in zero (deleted)[5648b9e00000+8000000]

The faulting instruction is inside an anonymous 0x8000000 (128M) mapping, which matches opcache.jit_buffer_size=128M, i.e. JIT-generated code.

No core dump or backtrace is available yet (the crashes stopped before one could be captured). I will add a backtrace and the failing command when the next burst happens.

Opcache settings (CLI):

opcache.enable=1
opcache.enable_cli=1
opcache.jit=tracing
opcache.jit_buffer_size=128M

Resulted in this output:

Segmentation fault (exit code 139)

But I expected this output instead:

The command completes normally.

PHP Version

PHP 8.5.12 (cli) (NTS), LiteSpeed lsphp85 build

Operating System

AlmaLinux 9, x86_64 (OpenLiteSpeed)

phuongvmhut avatar Nov 18 '26 12:11 phuongvmhut

Hi!

I'm seeing a very similar issue with PHP 8.5.13, while running a Laravel scheduled command (php artisan schedule:run).

I managed to analyze one of the core dumps with GDB, and here's what I found.

Environment:

  • PHP 8.5.13 (CLI, NTS)
  • Debian 13, x86_64 (Docker)
  • OPcache enabled for CLI
  • JIT: tracing, 64 MB buffer

GDB results:

Program terminated with signal SIGSEGV

si_code = 2 (SEGV_ACCERR)
si_addr = 0x55eb38e5572f

rip = 0x55eb34c003df
rcx = 0x55eb38e5572f

=> 0x55eb34c003df: mov %dx,(%rcx)

Relevant memory mappings:

0x55eb24c00000 - 0x55eb34c00000  256 MB  /dev/zero (deleted)
0x55eb34c00000 - 0x55eb38c00000   64 MB  /dev/zero (deleted)
0x55eb38e00000 - 0x55eb39601000          /usr/local/bin/php

The crash happens inside what appears to be the 64 MB JIT buffer.

The instruction tries to write to an address in the PHP executable's read/execute segment, which isn't writable.

It's slightly different from the original report here, but both crashes seem to happen in the JIT area.

Hopefully this helps! Happy to run a few more checks if needed. 🙂

DooSys avatar Nov 24 '26 10:11 DooSys

Also reproducing on 8.5.13: schedule:run segfaults on exit, stops with opcache.jit=0

Same pattern as the original report, on the official invoiceninja/invoiceninja-debian:5.14.1 image (Laravel, PHP from docker-library/php).

Environment

PHP 8.5.13 (cli) (built: Nov 24 2026 04:21:01) (NTS), Zend OPcache v8.5.13 x86_64, Intel Core i5-7500 @ 3.40GHz, 4 vCPUs (Docker in an LXC container on Proxmox) opcache.enable=On, opcache.enable_cli=On, opcache.jit=tracing, opcache.jit_buffer_size=64M, opcache.jit_hot_loop=61, opcache.memory_consumption=256 opcache.preload=/var/www/html/preload.php Extensions: bcmath, ctype, curl, date, dom, exif, fileinfo, filter, gd, hash, iconv, imagick, intl, json, lexbor, libxml, mbstring, mysqlnd, openssl, pcntl, pcre, PDO, pdo_mysql, pdo_sqlite, Phar, posix, random, readline, Reflection, saxonc, session, SimpleXML, soap, sodium, SPL, sqlite3, standard, tokenizer, uri, xml, xmlreader, xmlwriter, zip, zlib

Behaviour

php artisan schedule:run is run every minute by supervisor. On the runs that dispatch jobs (:00, :10 and :30 past each hour; QueueSize, ReminderJob, TaskScheduler, CleanStaleInvoiceOrder), every job logs DONE, and then about 0.6 s later the process dies with Segmentation fault (core dumped). The jobs complete; the crash is at process exit. About 3 crashes an hour: 66 in about 21 hours. Every core file is exactly 439 MB, matching DooSys's measurement above. Started right after upgrading from an image built before 24 Nov. The older image ran for 5 days without a crash.

Workaround result

With opcache.jit=0 and opcache.jit_buffer_size=0 (OPcache and preload still enabled, including CLI): 0 segfaults in the first hour, covering the six job-dispatching scheduler runs that had crashed every time before. With the JIT back on (tracing, 64M), the same container crashed 6 times in 2 hours.

Happy to collect a gdb backtrace from a core file if it would help.

kahlerisms avatar Nov 29 '26 22:11 kahlerisms