[php-src] PR #25483: Fix opcache.enable_file_override lookups racing with OPcache restarts

From: Date: Mon, 16 Nov 2026 12:28:31 +0000
Subject: [php-src] PR #25483: Fix opcache.enable_file_override lookups racing with OPcache restarts
Groups: php.git-pulls 
Request: Send a blank email to git-pulls+get-40676@lists.php.net to get a copy of this message
Pull Request: https://github.com/php/php-src/pull/25483 Author: pavimus Prepared with an AI assistant (Claude), which also ran the reproduction and the tests on my machine; I reviewed the result. The text below is AI-generated (quoted, as asked in CONTRIBUTING.md). > Found while working on OPcache restarts in threaded SAPIs (#24276), where @arnaud-lb asked to > be > pinged on this PR. It affects NTS as well (e.g. FPM) and is independent of #24276. > > With opcache.enable_file_override=1, > file_exists(), is_file() and > is_readable() first look > the file up in the shared hash (filename_is_in_cache()). Unlike > other readers of the shared > hash outside of compilation (accelerator_get_scripts(), > zend_accel_invalidate()), the lookup > neither checks ZCG(accelerator_enabled) nor takes the SHM read > lock (opcache_is_script_cached() > uses the same function after checking only > ZCG(accelerator_enabled)). A restart waits only for > processes that hold the read lock, so a request that is not counted as a reader (for example > one > that started while the restart was pending, when the cache is disabled for it) can look the > hash > up while another process is cleaning it in > zend_accel_hash_clean() / > zend_shared_alloc_restore_state(), and then read the script > entry it found. > > The window can be shown deterministically with gdb (NTS debug build, php > -S with > PHP_CLI_SERVER_WORKERS=2, > enable_file_override=1): > opcache_reset(), then a request that runs > the restart in RINIT is held by gdb at zend_accel_hash_clean(), > and meanwhile another worker > serves is_file(__DIR__ . '/a.php'). Without the fix > that worker calls zend_accel_hash_find() > on the shared hash with ZCSG(restart_in_progress) set and > ZCG(accelerator_enabled) false > (3/3 runs); with the fix it falls back to the original function during the restart and looks > the > hash up normally afterwards (3/3). I did not get a crash from this small case; there is no > .phpt, since it needs one process stopped inside the restart. > > The fix does what accelerator_get_scripts() does: look the hash > up only when the cache is > enabled for the request and accelerator_shm_read_lock() > succeeds, release it afterwards, and > otherwise fall back to the original function. With #24276, under ZTS this means that only > requests admitted in RINIT look the hash up. > > Tests: ext/opcache and > Zend/tests on NTS and ZTS debug builds, 0 failures (same as without > the > fix), including the file override tests issue0140.phpt and > bug74663.phpt. The change merges > into PHP-8.5 cleanly; on master filename_is_in_cache() returns > bool, the same change adapted > is ready if needed. 🤖 Generated with [Claude Code](https://claude.com/claude-code)

« previous php.git-pulls (#40676) next »