MediaWikiServices: Don't assume, that old and new instances contains the same services
authorFlorian Schmidt <florian.schmidt.stargatewissen@gmail.com>
Sun, 28 Aug 2016 16:33:40 +0000 (18:33 +0200)
committerAaron Schulz <aschulz@wikimedia.org>
Tue, 30 Aug 2016 14:17:04 +0000 (14:17 +0000)
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

index 49891df..037e96f 100644 (file)
@@ -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 */