Page MenuHomePhabricator

Warning: User::loadFromSession called before the end of Setup.php
Closed, ResolvedPublic0.25 Estimated Story PointsBUG REPORT

Description

Error
message
User::loadFromSession called before the end of Setup.php
trace
from /srv/mediawiki/1.43/includes/user/User.php(365)
#0 /srv/mediawiki/1.43/includes/user/User.php(1582): MediaWiki\User\User->load()
#1 /srv/mediawiki/1.43/includes/user/User.php(3240): MediaWiki\User\User->getName()
#2 /srv/mediawiki/1.43/extensions/GlobalBlocking/includes/Services/GlobalBlockLookup.php(208): MediaWiki\User\User->equals(MediaWiki\User\User)
#3 /srv/mediawiki/1.43/extensions/GlobalBlocking/includes/Services/GlobalBlockLookup.php(93): MediaWiki\Extension\GlobalBlocking\Services\GlobalBlockLookup->getUserBlockDetails(MediaWiki\User\User, string)
#4 /srv/mediawiki/1.43/extensions/GlobalBlocking/includes/GlobalBlockingHooks.php(99): MediaWiki\Extension\GlobalBlocking\Services\GlobalBlockLookup->getUserBlock(MediaWiki\User\User, string)
#5 /srv/mediawiki/1.43/includes/HookContainer/HookContainer.php(159): MediaWiki\Extension\GlobalBlocking\GlobalBlockingHooks->onGetUserBlock(MediaWiki\User\User, string, null)
#6 /srv/mediawiki/1.43/includes/HookContainer/HookRunner.php(2006): MediaWiki\HookContainer\HookContainer->run(string, array)
#7 /srv/mediawiki/1.43/includes/block/BlockManager.php(223): MediaWiki\HookContainer\HookRunner->onGetUserBlock(MediaWiki\User\User, string, null)
#8 /srv/mediawiki/1.43/includes/block/BlockManager.php(264): MediaWiki\Block\BlockManager->getBlock(MediaWiki\User\User, MediaWiki\Request\WebRequest, bool)
#9 /srv/mediawiki/1.43/includes/Permissions/PermissionManager.php(852): MediaWiki\Block\BlockManager->getCreateAccountBlock(MediaWiki\User\User, MediaWiki\Request\WebRequest, bool)
#10 /srv/mediawiki/1.43/includes/Permissions/PermissionManager.php(782): MediaWiki\Permissions\PermissionManager->getApplicableBlock(string, MediaWiki\User\User, string, MediaWiki\Title\Title, MediaWiki\Request\WebRequest)
#11 /srv/mediawiki/1.43/includes/Permissions/PermissionManager.php(507): MediaWiki\Permissions\PermissionManager->checkUserBlock(string, MediaWiki\User\User, MediaWiki\Permissions\PermissionStatus, string, bool, MediaWiki\Title\Title)
#12 /srv/mediawiki/1.43/includes/Permissions/UserAuthority.php(372): MediaWiki\Permissions\PermissionManager->getPermissionStatus(string, MediaWiki\User\User, MediaWiki\Title\Title, string)
#13 /srv/mediawiki/1.43/includes/Permissions/UserAuthority.php(251): MediaWiki\Permissions\UserAuthority->internalCan(string, string, MediaWiki\Title\Title, MediaWiki\Permissions\PermissionStatus, int)
#14 /srv/mediawiki/1.43/includes/user/User.php(3332): MediaWiki\Permissions\UserAuthority->authorizeWrite(string, MediaWiki\Title\Title, MediaWiki\Permissions\PermissionStatus)
#15 /srv/mediawiki/1.43/includes/auth/AuthManager.php(2169): MediaWiki\User\User->authorizeWrite(string, MediaWiki\Title\Title, MediaWiki\Permissions\PermissionStatus)
#16 /srv/mediawiki/1.43/includes/auth/AuthManager.php(1266): MediaWiki\Auth\AuthManager::MediaWiki\Auth\{closure}(string, MediaWiki\Title\Title, MediaWiki\Permissions\PermissionStatus)
#17 /srv/mediawiki/1.43/includes/auth/AuthManager.php(2163): MediaWiki\Auth\AuthManager->authorizeInternal(Closure, string)
#18 /srv/mediawiki/1.43/includes/auth/AuthManager.php(2005): MediaWiki\Auth\AuthManager->authorizeAutoCreateAccount(MediaWiki\User\User)
#19 /srv/mediawiki/1.43/includes/Setup.php(587): MediaWiki\Auth\AuthManager->autoCreateUser(MediaWiki\User\User, string, bool, bool, MediaWiki\User\User)
#20 /srv/mediawiki/1.43/includes/WebStart.php(85): require_once(string)
#21 /srv/mediawiki/config/initialise/entrypoints/index.php(12): require(string)
#22 {main}

Also triggered through:

trace
from /srv/mediawiki/php-1.45.0-wmf.13/includes/user/User.php(392)
#0 /srv/mediawiki/php-1.45.0-wmf.13/includes/user/User.php(1567): MediaWiki\User\User->load()
#1 /srv/mediawiki/php-1.45.0-wmf.13/includes/user/User.php(2135): MediaWiki\User\User->getId()
#2 /srv/mediawiki/php-1.45.0-wmf.13/includes/user/UserIdentityUtils.php(42): MediaWiki\User\User->isRegistered()
#3 /srv/mediawiki/php-1.45.0-wmf.13/includes/user/Options/ConditionalDefaultsLookup.php(155): MediaWiki\User\UserIdentityUtils->isNamed(MediaWiki\User\User)
#4 /srv/mediawiki/php-1.45.0-wmf.13/includes/user/Options/ConditionalDefaultsLookup.php(110): MediaWiki\User\Options\ConditionalDefaultsLookup->checkConditionForUser(MediaWiki\User\User, array)
#5 /srv/mediawiki/php-1.45.0-wmf.13/includes/user/Options/ConditionalDefaultsLookup.php(93): MediaWiki\User\Options\ConditionalDefaultsLookup->checkConditionsForUser(MediaWiki\User\User, array)
#6 /srv/mediawiki/php-1.45.0-wmf.13/includes/user/Options/DefaultOptionsLookup.php(147): MediaWiki\User\Options\ConditionalDefaultsLookup->getOptionDefaultForUser(string, MediaWiki\User\User)
#7 /srv/mediawiki/php-1.45.0-wmf.13/includes/user/Options/UserOptionsManager.php(552): MediaWiki\User\Options\DefaultOptionsLookup->getDefaultOptions(MediaWiki\User\User)
#8 /srv/mediawiki/php-1.45.0-wmf.13/includes/user/Options/UserOptionsManager.php(454): MediaWiki\User\Options\UserOptionsManager->loadOriginalOptions(MediaWiki\User\User, int)
#9 /srv/mediawiki/php-1.45.0-wmf.13/includes/user/Options/UserOptionsManager.php(177): MediaWiki\User\Options\UserOptionsManager->loadUserOptions(MediaWiki\User\User, int)
#10 /srv/mediawiki/php-1.45.0-wmf.13/includes/context/RequestContext.php(471): MediaWiki\User\Options\UserOptionsManager->getOption(MediaWiki\User\User, string)
#11 /srv/mediawiki/php-1.45.0-wmf.13/includes/ServiceWiring.php(613): MediaWiki\Context\RequestContext->getLanguage()
#12 /srv/mediawiki/php-1.45.0-wmf.13/vendor/wikimedia/services/src/ServiceContainer.php(442): Wikimedia\Services\ServiceContainer::{closure}(MediaWiki\MediaWikiServices)
#13 /srv/mediawiki/php-1.45.0-wmf.13/vendor/wikimedia/services/src/ServiceContainer.php(406): Wikimedia\Services\ServiceContainer->createService(string)
#14 /srv/mediawiki/php-1.45.0-wmf.13/includes/MediaWikiServices.php(371): Wikimedia\Services\ServiceContainer->getService(string)
#15 /srv/mediawiki/php-1.45.0-wmf.13/includes/MediaWikiServices.php(942): MediaWiki\MediaWikiServices->getService(string)
#16 /srv/mediawiki/php-1.45.0-wmf.13/includes/ServiceWiring.php(603): MediaWiki\MediaWikiServices->getCommentParserFactory()
#17 /srv/mediawiki/php-1.45.0-wmf.13/vendor/wikimedia/services/src/ServiceContainer.php(442): Wikimedia\Services\ServiceContainer::{closure}(MediaWiki\MediaWikiServices)
#18 /srv/mediawiki/php-1.45.0-wmf.13/vendor/wikimedia/services/src/ServiceContainer.php(406): Wikimedia\Services\ServiceContainer->createService(string)
#19 /srv/mediawiki/php-1.45.0-wmf.13/includes/MediaWikiServices.php(371): Wikimedia\Services\ServiceContainer->getService(string)
#20 /srv/mediawiki/php-1.45.0-wmf.13/vendor/wikimedia/services/src/ServiceContainer.php(414): MediaWiki\MediaWikiServices->getService(string)
#21 /srv/mediawiki/php-1.45.0-wmf.13/vendor/wikimedia/object-factory/src/ObjectFactory.php(204): Wikimedia\Services\ServiceContainer->get(string)
#22 /srv/mediawiki/php-1.45.0-wmf.13/vendor/wikimedia/object-factory/src/ObjectFactory.php(149): Wikimedia\ObjectFactory\ObjectFactory::getObjectFromSpec(array, array)
#23 /srv/mediawiki/php-1.45.0-wmf.13/includes/HookContainer/HookContainer.php(252): Wikimedia\ObjectFactory\ObjectFactory->createObject(array)
#24 /srv/mediawiki/php-1.45.0-wmf.13/includes/HookContainer/HookContainer.php(344): MediaWiki\HookContainer\HookContainer->makeExtensionHandlerCallback(string, array, array)
#25 /srv/mediawiki/php-1.45.0-wmf.13/includes/HookContainer/HookContainer.php(520): MediaWiki\HookContainer\HookContainer->normalizeHandler(string, array, array)
#26 /srv/mediawiki/php-1.45.0-wmf.13/includes/HookContainer/HookContainer.php(142): MediaWiki\HookContainer\HookContainer->getHandlers(string, array)
#27 /srv/mediawiki/php-1.45.0-wmf.13/includes/HookContainer/HookRunner.php(2213): MediaWiki\HookContainer\HookContainer->run(string, array)
#28 /srv/mediawiki/php-1.45.0-wmf.13/includes/block/BlockManager.php(227): MediaWiki\HookContainer\HookRunner->onGetUserBlock(MediaWiki\User\User, string, null)
#29 /srv/mediawiki/php-1.45.0-wmf.13/includes/block/BlockManager.php(266): MediaWiki\Block\BlockManager->getBlock(MediaWiki\User\User, MediaWiki\Request\WebRequest, bool)
#30 /srv/mediawiki/php-1.45.0-wmf.13/includes/Permissions/PermissionManager.php(873): MediaWiki\Block\BlockManager->getCreateAccountBlock(MediaWiki\User\User, MediaWiki\Request\WebRequest, bool)
#31 /srv/mediawiki/php-1.45.0-wmf.13/includes/Permissions/PermissionManager.php(808): MediaWiki\Permissions\PermissionManager->getApplicableBlock(string, MediaWiki\User\User, string, MediaWiki\Title\Title, MediaWiki\Request\WebRequest)
#32 /srv/mediawiki/php-1.45.0-wmf.13/includes/Permissions/PermissionManager.php(528): MediaWiki\Permissions\PermissionManager->checkUserBlock(string, MediaWiki\User\User, MediaWiki\Permissions\PermissionStatus, string, bool, MediaWiki\Title\Title)
#33 /srv/mediawiki/php-1.45.0-wmf.13/includes/Permissions/UserAuthority.php(362): MediaWiki\Permissions\PermissionManager->getPermissionStatus(string, MediaWiki\User\User, MediaWiki\Title\Title, string)
#34 /srv/mediawiki/php-1.45.0-wmf.13/includes/Permissions/UserAuthority.php(256): MediaWiki\Permissions\UserAuthority->internalCan(string, string, MediaWiki\Title\Title, MediaWiki\Permissions\PermissionStatus, int)
#35 /srv/mediawiki/php-1.45.0-wmf.13/includes/user/User.php(3396): MediaWiki\Permissions\UserAuthority->authorizeWrite(string, MediaWiki\Title\Title, MediaWiki\Permissions\PermissionStatus)
#36 /srv/mediawiki/php-1.45.0-wmf.13/includes/auth/AuthManager.php(2241): MediaWiki\User\User->authorizeWrite(string, MediaWiki\Title\Title, MediaWiki\Permissions\PermissionStatus)
#37 /srv/mediawiki/php-1.45.0-wmf.13/includes/auth/AuthManager.php(1224): MediaWiki\Auth\AuthManager::MediaWiki\Auth\{closure}(string, MediaWiki\Title\Title, MediaWiki\Permissions\PermissionStatus)
#38 /srv/mediawiki/php-1.45.0-wmf.13/includes/auth/AuthManager.php(2243): MediaWiki\Auth\AuthManager->authorizeInternal(Closure, string)
#39 /srv/mediawiki/php-1.45.0-wmf.13/includes/auth/AuthManager.php(2056): MediaWiki\Auth\AuthManager->authorizeAutoCreateAccount(MediaWiki\User\User)
#40 /srv/mediawiki/php-1.45.0-wmf.13/includes/Setup.php(606): MediaWiki\Auth\AuthManager->autoCreateUser(MediaWiki\User\User, string, bool, bool, MediaWiki\User\User)
#41 /srv/mediawiki/php-1.45.0-wmf.13/includes/WebStart.php(86): require_once(string)
#42 /srv/mediawiki/php-1.45.0-wmf.13/index.php(50): require(string)
#43 /srv/mediawiki/w/index.php(3): require(string)
#44 {main}
Impact

User was logged out eventually due to autocreation failing with globalblocking-blockedtext-range and then the session store entry is for an anonymous user, but the session metadata indicates a non-anonynmous user and then Failed to load session, unpersisting and then Metadata merge failed: MediaWiki\Session\MetadataMergeException: Key "CentralAuthSource" changed in /srv/mediawiki/1.43/includes/session/SessionProvider.php:338

The ::loadFromSession warning was triggered 8 times in a row. It's a warning so not too bad but feels worth reporting. The message accounts for around 0.4% of our logs. I haven't checked if they are all the same trace though.

Notes

Acceptance criteria

  • The logs given above do not appear on WMF production anymore
  • The fixes made are backported to at least MW-1.43-release

Event Timeline

Aklapper changed the subtype of this task from "Production Error" to "Bug Report".Jun 26 2025, 3:08 PM

This can likely be fixed by not comparing against the session user unless we need to.

We will need to address this soon as it's causing 100,000s of warnings in logstash in the last week.

Change #1174758 had a related patch set uploaded (by Dreamy Jazz; author: Dreamy Jazz):

[mediawiki/extensions/GlobalBlocking@master] GlobalBlockLookup: Don't call ContextSource::getUser unless safe

https://gerrit.wikimedia.org/r/1174758

Dreamy_Jazz set the point value for this task to 0.25.
kostajh subscribed.

For QA, let's verify that the Logstash warning are no longer present when wmf.13 rolls out.

Change #1174758 merged by jenkins-bot:

[mediawiki/extensions/GlobalBlocking@master] GlobalBlockLookup: Don't call ContextSource::getUser unless safe

https://gerrit.wikimedia.org/r/1174758

OKryva-WMF triaged this task as Medium priority.Aug 1 2025, 1:46 PM

It didn't solve the issue entirely though massively reduced the logs.

Now we are seeing it trigger through getting the CommentFormatter service which uses the CommentParserFactory service which then attempts to get the language from the main request context. This will eventually trigger inspecting the main request user which causes this problem.

We can fix that by making CommentParserFactory lazily load the language in the CommentParserFactory::create method instead of passing it through the constructor.

Change #1176306 had a related patch set uploaded (by Dreamy Jazz; author: Dreamy Jazz):

[mediawiki/core@master] Don't use RequestContext in CommentParserFactory construction

https://gerrit.wikimedia.org/r/1176306

Change #1176307 had a related patch set uploaded (by Dreamy Jazz; author: Dreamy Jazz):

[mediawiki/extensions/GlobalBlocking@REL1_44] GlobalBlockLookup: Don't call ContextSource::getUser unless safe

https://gerrit.wikimedia.org/r/1176307

Change #1176308 had a related patch set uploaded (by Dreamy Jazz; author: Dreamy Jazz):

[mediawiki/extensions/GlobalBlocking@REL1_43] GlobalBlockLookup: Don't call ContextSource::getUser unless safe

https://gerrit.wikimedia.org/r/1176308

Having looked at several other examples of these errors, there are a lot which are not caused by GlobalBlocking code. Therefore, I will filter these logs to exclude those which do not include GlobalBlocking in the stack trace.

Change #1176307 merged by jenkins-bot:

[mediawiki/extensions/GlobalBlocking@REL1_44] GlobalBlockLookup: Don't call ContextSource::getUser unless safe

https://gerrit.wikimedia.org/r/1176307

Change #1176308 merged by jenkins-bot:

[mediawiki/extensions/GlobalBlocking@REL1_43] GlobalBlockLookup: Don't call ContextSource::getUser unless safe

https://gerrit.wikimedia.org/r/1176308

Change #1176306 merged by jenkins-bot:

[mediawiki/core@master] Don't use RequestContext in CommentParserFactory construction

https://gerrit.wikimedia.org/r/1176306

Will need to wait for the next train to verify that the other fix also worked

The second fix (the MediaWiki core one) seems to reduce many more logs than the other one (though both are still needed).

For example https://logstash.wikimedia.org/goto/1204feae3a5687f4dc1e81bc7fd37a3b shows all such warnings fixed by the second patch (2 million in the last week).

Therefore, we should probably also backport the fix to MediaWiki core as well to fix the logs for affects-Miraheze.

There are also a million other such warnings in the last week, but these do not appear to be caused by us (instead the Vector (legacy skin) skin).

There are also a million other such warnings in the last week, but these do not appear to be caused by us (instead the Vector (legacy skin) skin).

I guess that should be split off into another task then

The second fix (the MediaWiki core one) seems to reduce many more logs than the other one (though both are still needed).

For example https://logstash.wikimedia.org/goto/1204feae3a5687f4dc1e81bc7fd37a3b shows all such warnings fixed by the second patch (2 million in the last week).

Therefore, we should probably also backport the fix to MediaWiki core as well to fix the logs for affects-Miraheze.

Thank you, sounds good.

There are also a million other such warnings in the last week, but these do not appear to be caused by us (instead the Vector (legacy skin) skin).

I guess that should be split off into another task then

Yes. I filed T401400 to cover that

Change #1180128 had a related patch set uploaded (by Dreamy Jazz; author: Dreamy Jazz):

[mediawiki/core@REL1_44] Don't use RequestContext in CommentParserFactory construction

https://gerrit.wikimedia.org/r/1180128

Change #1180129 had a related patch set uploaded (by Dreamy Jazz; author: Dreamy Jazz):

[mediawiki/core@REL1_43] Don't use RequestContext in CommentParserFactory construction

https://gerrit.wikimedia.org/r/1180129

Change #1180131 had a related patch set uploaded (by Dreamy Jazz; author: Dreamy Jazz):

[mediawiki/core@REL1_39] Don't use RequestContext in CommentParserFactory construction

https://gerrit.wikimedia.org/r/1180131

Change #1180131 abandoned by Dreamy Jazz:

[mediawiki/core@REL1_39] Don't use RequestContext in CommentParserFactory construction

https://gerrit.wikimedia.org/r/1180131

Change #1180129 merged by jenkins-bot:

[mediawiki/core@REL1_43] Don't use RequestContext in CommentParserFactory construction

https://gerrit.wikimedia.org/r/1180129

Change #1180128 merged by jenkins-bot:

[mediawiki/core@REL1_44] Don't use RequestContext in CommentParserFactory construction

https://gerrit.wikimedia.org/r/1180128

Fixed the warnings that are caused by GlobalBlocking. There are other instances of these logs, but these are not caused by GlobalBlocking and so should be addressed in other tickets.