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
(cherry picked from commit 0b1480e60ef7d649bf7d22de5a7c032d04ed0f7a)
This commit is contained in:
Máté Szabó 2025-01-17 15:49:29 +01:00 committed by Reedy
parent bbd7861a38
commit c3bdae9eca

View file

@ -795,6 +795,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 ) {