Repository navigation
Load the CMS code cache by its declared class instead of with require_once - #1570
Merged
LukeTowers merged 3 commits intoOct 16, 2026
Merged
LukeTowers merged 3 commits into
LukeTowers merged 3 commits into
Conversation
CodeParser::rebuild() writes the generated class to a fixed path, but gives the class a new random name on every rebuild. require_once keys on the path, so after the first rebuild of an object in a process, later rebuilds left their class undeclared and the page failed with "Class Cms...Class not found". This also defeated handleCorruptCache(), which rebuilds and then loads the result. require cannot redeclare anything, because each rebuild's class name is unique.
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…er a rebuild source() still loaded the cache file with require_once, so a process that had loaded the path before skipped a rebuild written by another process. handleCorruptCache() then deleted and rebuilt the file, which invalidated the other process in turn. rebuild(), source() and handleCorruptCache() now share requireClassFile(), which requires the file only when the class it declares is not loaded yet, so require can never redeclare a class.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Cms\Classes\CodeParserwrites the generated class for a page's PHP code section to a fixed path, but gives the class a new random name on every rebuild. Bothrebuild()andsource()loaded that file withrequire_once, which keys on the path, so a process that had already loaded the path skipped every later version of the file and the page failed:The later version can come from the same process or from another one. With several long-running workers (Laravel Octane, or queue workers rendering pages), worker B's rebuild is skipped by worker A, whose
handleCorruptCache()then deletes and rebuilds the file, which invalidates worker B in turn. The workers keep rebuilding each other after every edit, and a third worker can hit the file while it is missing.All three paths now load the file through
requireClassFile(), which reads the class name the file declares and usesrequireonly when that class is not loaded yet.requiretherefore never redeclares a class, and a new version of the file is always loaded. PHP-FPM behavior does not change, since each request starts with nothing loaded.Split out of #1511 so it can be reviewed on its own.
Testing
modules/cms/tests/classes/CodeParserRebuildTest.phpcovers two rebuilds in one process and a rebuild written by another process (same path, new class name) thatsource()must load. Both fail without the change. The full CMS module suite passes (221 tests).