aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMáté Szabó <mszabo@wikimedia.org>2025-01-17 15:49:29 +0100
committerMáté Szabó <mszabo@wikimedia.org>2025-01-17 15:49:29 +0100
commit0b1480e60ef7d649bf7d22de5a7c032d04ed0f7a (patch)
tree99d73e2c09c1abbe9fadf9d5af485e619407d9c4
parent795405e35971ea418953a4667476ddda2f121d20 (diff)
downloadmediawikicore-0b1480e60ef7d649bf7d22de5a7c032d04ed0f7a.tar.gz
mediawikicore-0b1480e60ef7d649bf7d22de5a7c032d04ed0f7a.zip
exception: Avoid service container init in exception handler
Why: - The exception handler may be triggered during service container initialization, e.g. if an autoloaded class triggers a deprecation warning. - This causes callLogExceptionHook() to try to setup the service container once again, which then causes a cryptic "class not found" error as the service container attempts to autoload whatever class triggered the deprecation warning once again and fails. What: - Avoid attempting to initialize the service container in our exception handler if it was not setup already, since it may be unsafe to do so. Bug: T380456 Change-Id: Ib439f25d9e309b77eac00c59c32e39ffbf3aa2a4
-rw-r--r--includes/exception/MWExceptionHandler.php8
1 files changed, 8 insertions, 0 deletions
diff --git a/includes/exception/MWExceptionHandler.php b/includes/exception/MWExceptionHandler.php
index 4ddb430b2267..1c3c1fdd80a3 100644
--- a/includes/exception/MWExceptionHandler.php
+++ b/includes/exception/MWExceptionHandler.php
@@ -794,6 +794,14 @@ TXT;
*/
private static function callLogExceptionHook( Throwable $e, bool $suppressed ) {
try {
+ // It's possible for the exception handler to be triggered during service container
+ // initialization, e.g. if an autoloaded file triggers deprecation warnings.
+ // To avoid a difficult-to-debug autoload loop, avoid attempting to initialize the service
+ // container here. (T380456).
+ if ( !MediaWikiServices::hasInstance() ) {
+ return;
+ }
+
( new HookRunner( MediaWikiServices::getInstance()->getHookContainer() ) )
->onLogException( $e, $suppressed );
} catch ( RecursiveServiceDependencyException $e ) {