Repository navigation
Avoid Monolog\Logger interceptor generation and harden isHandling() against bootstrap errors - #252
Open
claudio-ferraro wants to merge 2 commits into
Open
claudio-ferraro wants to merge 2 commits into
claudio-ferraro wants to merge 2 commits into
Conversation
…gainst bootstrap errors
1 of 2 tasks
indykoning
reviewed
Aug 20, 2026
…and Helper\Data fixes
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
Investigating #242 (three reported circular DI fatals on Magento 2.4.9
setup:upgrade), I reproduced the crash on a fresh, isolated Magento 2.4.9 install (core modules + this module only), this directly answers @indykoning's question in the issue thread: it is not caused by an incompatibility with another extension, it reproduces standalone.Isolating each of the three reported causes individually showed the actual
FrontendPool↔CompiledConfigcircular dependency is fully explained by cause 3, theCache\Frontend\Factoryconstructor mismatch, that's the one genuinely Magento-2.4.9-specific bug here (2.4.9 added a new constructor argument to the core class), and it's already fixed onmaster(#239). With only that fix applied, and theMonolog\Loggerplugin (cause 1) left completely untouched,setup:upgradecompletes without error on a fresh 2.4.9 install.So this PR is not a Magento 2.4.9 compatibility fix, causes 1 and 2 turn out not to be version-specific at all. The
Monolog\Loggerplugin has been unchanged since it was added in v4.3.0 and runs the same way on 2.4.8;Magento\Framework\Logger\Monologand Magento'smonolog/monologconstraint (^3.6) are identical between 2.4.8-p5 and 2.4.9. They only ever surfaced here because cause 3's TypeError happened to log through this exact path during bootstrap. Without a trigger like that, causes 1/2 sit dormant on any Magento version.That said, they're real latent fragility worth hardening on their own merit:
di.xmlregistered a<plugin>directly on the third-partyMonolog\Loggerclass. A plugin on a vendor class forces Magento to generate anInterceptorfor it, which, depending on exactly when that first happens, can itself produce a circular dependency (FrontendPool → ResourceConnection → LoggerProxy → Monolog\Logger\Interceptor → PluginList::getNext() → CompiledConfig → FrontendPool, as also reported by @simonmaass). Wiring the handler into Magento's ownMagento\Framework\Logger\Monologvia constructor argument (the same mechanism Magento itself uses for adding handlers) needs no interceptor at all, soPlugin/MonologPlugin.phpis now unused and removed.Logger\Handler\Sentry::isHandling()had no error handling. If anything gets logged while the DI container is still mid-construction,isHandling()resolvesHelper\Data\Proxy→ the realHelper\Data, whose constructor eagerly calledcollectModuleConfig()and could re-enter config/cache resolution that's already in progress.isHandling()now catches\Throwableand returnsfalse, andHelper\Datano longer eagerly collects config in its constructor (it was already lazily memoized per store, so nothing changes for the normal path).Related: #242
Result
Verified on Magento 2.4.9 (fresh install, core modules + JustBetter_Sentry only):
bin/magento setup:install/setup:upgrade/setup:di:compileall complete without errors, with the Sentry Monolog handler wired via constructor argument.setup:upgradecompletes without any new errors.Checklist
composer run codestylecomposer run analyse