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

Copy link
Copy Markdown

AI-assisted implementation and PR description

Summary

  • Restore the pre-error GC protection state after a direct compiler error caught by opcache_compile_file()
  • Preserve protection for runtime fatals, errors that unwind user callbacks and an already protected collector
  • Keep the existing diagnostics, false return value and preload failure behavior

Implementation

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

Restore protection only for E_COMPILE_ERROR from the current opcache_compile_file() frame and when no OOM has occurred

The observer avoids relying on last_error_type, which can remain stale when repeated errors are suppressed, including when a later runtime fatal has the same message

Verification

  • Reproduced on unmodified revision 7c0b9008963e0fbffd4d71f92e01e2ac2b8ec410, GC becomes protected and collects zero cycles after the reported failure
  • The same reproduction after the fix keeps GC unprotected and collects 99999 cycles
  • Add five PHPT tests covering manual and automatic GC, uncached compilation, disabled automatic GC, a throwing warning handler, repeated errors, nested fatal compilation and memory exhaustion
  • Regression tests pass with debug NTS and ZTS builds in shared-memory, file-cache-only and tracing JIT modes
  • Zend, OPcache, zend_test, language and basic suites on macOS ARM64 have no unexpected failures
  • NTS results are 6375 passed, 202 skipped and 2 expected failures
  • ZTS results are 6371 passed, 206 skipped and 2 expected failures

Fixes #24361

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 47c23e5 to acde4be Compare November 6, 2026 03:56
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