From acfb8efed82f2514625324cb508be8abaa567f0c Mon Sep 17 00:00:00 2001 From: Florian Schmidt Date: Sun, 28 Aug 2016 18:33:40 +0200 Subject: [PATCH] MediaWikiServices: Don't assume, that old and new instances contains the same services As the services, that are registered in MediaWikiServices can be changed by extensions using the MediaWikiServices hook, it's not save to assume, that the first created instance of MediaWikiServices (which could be created before any extension is loaded, e.g. in ExtensionRegistry) contains the same services as a later created one (in the reset process of resetGlobalInstance). Doing this could result in a NoSuchServiceException, if an extension registers new services, which aren't registered before the extension is loaded (as, in the reset process, MediaWikiServices tries to minimize the service instantiation cost by preserving services, that can be preserved). This patch adds a check, if a service is registered in the MediaWikiServices object that should be reset, before the salvage-logic tries to fetch the services. If the service object does not exist, it simply skips it, as it will simply instantiated later. Follow up: Ie2ca3ff99aa74fffa9eb6c8faccab857dc0874f7 Follow up: I2a26b6af07a48ad15414a8428daa9cfcfe02e933 Bug: T143974 Change-Id: Ifc587d6138ab565c2f38eb0805acf0dd0473d433 --- includes/MediaWikiServices.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/includes/MediaWikiServices.php b/includes/MediaWikiServices.php index 49891dfd5e..037e96ffa8 100644 --- a/includes/MediaWikiServices.php +++ b/includes/MediaWikiServices.php @@ -198,7 +198,14 @@ class MediaWikiServices extends ServiceContainer { */ private function salvage( self $other ) { foreach ( $this->getServiceNames() as $name ) { - $oldService = $other->peekService( $name ); + // The service could be new in the new instance and not registered in the + // other instance (e.g. an extension that was loaded after the instantiation of + // the other instance. Skip this service in this case. See T143974 + try { + $oldService = $other->peekService( $name ); + } catch ( NoSuchServiceException $e ) { + continue; + } if ( $oldService instanceof SalvageableService ) { /** @var SalvageableService $newService */ -- 2.20.1