Skip to content

Fix GH-24361: Restore GC after opcache_compile_file errors - #25202

Open
akasakariko wants to merge 1 commit into
php:PHP-8.4from
akasakariko:fix/gh-24361-opcache-compile-gc
Open

akasakariko wants to merge 1 commit into
php:PHP-8.4from
akasakariko:fix/gh-24361-opcache-compile-gc

Conversation

@akasakariko

@akasakariko akasakariko commented Nov 5, 2026 •

Copy link
Copy Markdown

Rebased onto the current target branch to resolve the NEWS conflict

Fixes #24361

zend_bailout() protects the GC while a fatal error unwinds, but opcache_compile_file() catches that bailout and returns false, so the request continues with the cycle collector disabled

Record the fatal error type, execution frame and GC protection state in a thread-local error observer before the bailout clears the execution frame

Restore the previous state only for E_COMPILE_ERROR raised in the current opcache_compile_file() frame and only when no OOM is pending

Runtime fatals, errors that unwind user callbacks, an already protected collector and preload failures keep their existing behavior, as do the diagnostics and the false return value

Reproduced on the unmodified target branch, GC becomes protected and gc_collect_cycles() returns 0 after the failed compile

After the change GC stays unprotected and gc_collect_cycles() collects the cycles

PHPT coverage checks manual and automatic collection, disabled automatic GC, a throwing warning handler, repeated errors, nested fatal compilation and memory exhaustion

Local verification on a debug NTS build, all five new tests pass, the OPcache suite has 985 tests with 944 passed, 1 expected failure, 40 skipped and 0 failures, the Zend suite has 5081 tests with 4931 passed, 1 expected failure, 149 skipped and 0 failures

The previous head passed the available CI matrix jobs, the rebased head will rerun them

Record fatal error origin before bailout and restore GC only for direct
compiler failures, preserving runtime fatal protection

Cover manual and automatic collection, error handlers and fatal callbacks
@akasakariko
akasakariko force-pushed the fix/gh-24361-opcache-compile-gc branch from acde4be to 02f5c54 Compare November 10, 2026 03:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant