Page MenuHomePhabricator

BetaFeatures causes User::loadFromSession called before the end of Setup.php
Closed, ResolvedPublicPRODUCTION ERROR

Description

Error message
User::loadFromSession called before the end of Setup.php

There are a few such errors, the one investigated was on wikidatawiki and the request sequence is roughly:

authenticationMediaWiki\Auth\AuthManager::autoCreateUser: creating new user XXX
preferencesCouldn't find a global ID for user XXX
CentralAuthAttaching local user XXX@wikidatawiki by 'login'
preferencesCouldn't find a global ID for user XXX
sessionmultiples User::loadFromSession called before the end of Setup.php
preferencesCouldn't find a global ID for user XXX
sessionPersisting session for unknown reason
autheventsAutocreation attempt

The five User::loadFromSession called before the end of Setup.php come when saving the UserOptions which triggers a BetaFeatures job to update the features usage counts. The job is passed Title::newMainPage() which loads a Language and the User while in Setup.php.

The traces from first to last:

Stack Trace
#0 /srv/mediawiki/php-1.36.0-wmf.10/includes/user/User.php(2024): User->load()
#1 /srv/mediawiki/php-1.36.0-wmf.10/includes/user/User.php(2963): User->getId()
#2 /srv/mediawiki/php-1.36.0-wmf.10/includes/user/UserOptionsManager.php(587): User->isRegistered()
#3 /srv/mediawiki/php-1.36.0-wmf.10/includes/user/UserOptionsManager.php(490): MediaWiki\User\UserOptionsManager->getCacheKey(User)
#4 /srv/mediawiki/php-1.36.0-wmf.10/includes/user/UserOptionsManager.php(138): MediaWiki\User\UserOptionsManager->loadUserOptions(User, integer)
#5 /srv/mediawiki/php-1.36.0-wmf.10/includes/user/User.php(2564): MediaWiki\User\UserOptionsManager->getOption(User, string, NULL, boolean)
#6 /srv/mediawiki/php-1.36.0-wmf.10/includes/context/RequestContext.php(351): User->getOption(string)
#7 /srv/mediawiki/php-1.36.0-wmf.10/includes/language/Message.php(391): RequestContext->getLanguage()
#8 /srv/mediawiki/php-1.36.0-wmf.10/includes/language/Message.php(1291): Message->getLanguage()
#9 /srv/mediawiki/php-1.36.0-wmf.10/includes/language/Message.php(849): Message->fetchMessage()
#10 /srv/mediawiki/php-1.36.0-wmf.10/includes/language/Message.php(941): Message->toString(string)
#11 /srv/mediawiki/php-1.36.0-wmf.10/includes/Title.php(660): Message->text()
#12 /srv/mediawiki/php-1.36.0-wmf.10/extensions/BetaFeatures/includes/BetaFeaturesHooks.php(93): Title::newMainPage()
#13 /srv/mediawiki/php-1.36.0-wmf.10/includes/HookContainer/HookContainer.php(331): BetaFeaturesHooks::updateUserCounts(User, array, array)
#14 /srv/mediawiki/php-1.36.0-wmf.10/includes/HookContainer/HookContainer.php(138): MediaWiki\HookContainer\HookContainer->callLegacyHook(string, array, array, array)
#15 /srv/mediawiki/php-1.36.0-wmf.10/includes/HookContainer/HookRunner.php(4450): MediaWiki\HookContainer\HookContainer->run(string, array)
#16 /srv/mediawiki/php-1.36.0-wmf.10/includes/user/UserOptionsManager.php(397): MediaWiki\HookContainer\HookRunner->onUserSaveOptions(User, array, array)
#17 /srv/mediawiki/php-1.36.0-wmf.10/includes/user/User.php(3401): MediaWiki\User\UserOptionsManager->saveOptions(User)
#18 /srv/mediawiki/php-1.36.0-wmf.10/includes/auth/AuthManager.php(1767): User->saveSettings()
#19 /srv/mediawiki/php-1.36.0-wmf.10/includes/Setup.php(812): MediaWiki\Auth\AuthManager->autoCreateUser(User, string, boolean)
#20 /srv/mediawiki/php-1.36.0-wmf.10/includes/WebStart.php(89): require_once(string)
#21 /srv/mediawiki/php-1.36.0-wmf.10/api.php(43): require(string)
#22 /srv/mediawiki/w/api.php(3): require(string)
#23 {main}
Stack Trace
#0 /srv/mediawiki/php-1.36.0-wmf.10/includes/user/User.php(2024): User->load()
#1 /srv/mediawiki/php-1.36.0-wmf.10/includes/user/User.php(2963): User->getId()
#2 /srv/mediawiki/php-1.36.0-wmf.10/includes/user/UserOptionsManager.php(499): User->isRegistered()
#3 /srv/mediawiki/php-1.36.0-wmf.10/includes/user/UserOptionsManager.php(138): MediaWiki\User\UserOptionsManager->loadUserOptions(User, integer)
#4 /srv/mediawiki/php-1.36.0-wmf.10/includes/user/User.php(2564): MediaWiki\User\UserOptionsManager->getOption(User, string, NULL, boolean)
#5 /srv/mediawiki/php-1.36.0-wmf.10/includes/context/RequestContext.php(351): User->getOption(string)
#6 /srv/mediawiki/php-1.36.0-wmf.10/includes/language/Message.php(391): RequestContext->getLanguage()
#7 /srv/mediawiki/php-1.36.0-wmf.10/includes/language/Message.php(1291): Message->getLanguage()
#8 /srv/mediawiki/php-1.36.0-wmf.10/includes/language/Message.php(849): Message->fetchMessage()
#9 /srv/mediawiki/php-1.36.0-wmf.10/includes/language/Message.php(941): Message->toString(string)
#10 /srv/mediawiki/php-1.36.0-wmf.10/includes/Title.php(660): Message->text()
#11 /srv/mediawiki/php-1.36.0-wmf.10/extensions/BetaFeatures/includes/BetaFeaturesHooks.php(93): Title::newMainPage()
#12 /srv/mediawiki/php-1.36.0-wmf.10/includes/HookContainer/HookContainer.php(331): BetaFeaturesHooks::updateUserCounts(User, array, array)
#13 /srv/mediawiki/php-1.36.0-wmf.10/includes/HookContainer/HookContainer.php(138): MediaWiki\HookContainer\HookContainer->callLegacyHook(string, array, array, array)
#14 /srv/mediawiki/php-1.36.0-wmf.10/includes/HookContainer/HookRunner.php(4450): MediaWiki\HookContainer\HookContainer->run(string, array)
#15 /srv/mediawiki/php-1.36.0-wmf.10/includes/user/UserOptionsManager.php(397): MediaWiki\HookContainer\HookRunner->onUserSaveOptions(User, array, array)
#16 /srv/mediawiki/php-1.36.0-wmf.10/includes/user/User.php(3401): MediaWiki\User\UserOptionsManager->saveOptions(User)
#17 /srv/mediawiki/php-1.36.0-wmf.10/includes/auth/AuthManager.php(1767): User->saveSettings()
#18 /srv/mediawiki/php-1.36.0-wmf.10/includes/Setup.php(812): MediaWiki\Auth\AuthManager->autoCreateUser(User, string, boolean)
#19 /srv/mediawiki/php-1.36.0-wmf.10/includes/WebStart.php(89): require_once(string)
#20 /srv/mediawiki/php-1.36.0-wmf.10/api.php(43): require(string)
#21 /srv/mediawiki/w/api.php(3): require(string)
#22 {main}
Stack Trace
#0 /srv/mediawiki/php-1.36.0-wmf.10/includes/user/User.php(2024): User->load()
#1 /srv/mediawiki/php-1.36.0-wmf.10/includes/user/User.php(2963): User->getId()
#2 /srv/mediawiki/php-1.36.0-wmf.10/includes/user/UserOptionsManager.php(606): User->isRegistered()
#3 /srv/mediawiki/php-1.36.0-wmf.10/includes/user/UserOptionsManager.php(491): MediaWiki\User\UserOptionsManager->canUseCachedValues(User, integer)
#4 /srv/mediawiki/php-1.36.0-wmf.10/includes/user/UserOptionsManager.php(138): MediaWiki\User\UserOptionsManager->loadUserOptions(User, integer)
#5 /srv/mediawiki/php-1.36.0-wmf.10/includes/user/User.php(2564): MediaWiki\User\UserOptionsManager->getOption(User, string, NULL, boolean)
#6 /srv/mediawiki/php-1.36.0-wmf.10/includes/context/RequestContext.php(351): User->getOption(string)
#7 /srv/mediawiki/php-1.36.0-wmf.10/includes/language/Message.php(391): RequestContext->getLanguage()
#8 /srv/mediawiki/php-1.36.0-wmf.10/includes/language/Message.php(1291): Message->getLanguage()
#9 /srv/mediawiki/php-1.36.0-wmf.10/includes/language/Message.php(849): Message->fetchMessage()
#10 /srv/mediawiki/php-1.36.0-wmf.10/includes/language/Message.php(941): Message->toString(string)
#11 /srv/mediawiki/php-1.36.0-wmf.10/includes/Title.php(660): Message->text()
#12 /srv/mediawiki/php-1.36.0-wmf.10/extensions/BetaFeatures/includes/BetaFeaturesHooks.php(93): Title::newMainPage()
#13 /srv/mediawiki/php-1.36.0-wmf.10/includes/HookContainer/HookContainer.php(331): BetaFeaturesHooks::updateUserCounts(User, array, array)
#14 /srv/mediawiki/php-1.36.0-wmf.10/includes/HookContainer/HookContainer.php(138): MediaWiki\HookContainer\HookContainer->callLegacyHook(string, array, array, array)
#15 /srv/mediawiki/php-1.36.0-wmf.10/includes/HookContainer/HookRunner.php(4450): MediaWiki\HookContainer\HookContainer->run(string, array)
#16 /srv/mediawiki/php-1.36.0-wmf.10/includes/user/UserOptionsManager.php(397): MediaWiki\HookContainer\HookRunner->onUserSaveOptions(User, array, array)
#17 /srv/mediawiki/php-1.36.0-wmf.10/includes/user/User.php(3401): MediaWiki\User\UserOptionsManager->saveOptions(User)
#18 /srv/mediawiki/php-1.36.0-wmf.10/includes/auth/AuthManager.php(1767): User->saveSettings()
#19 /srv/mediawiki/php-1.36.0-wmf.10/includes/Setup.php(812): MediaWiki\Auth\AuthManager->autoCreateUser(User, string, boolean)
#20 /srv/mediawiki/php-1.36.0-wmf.10/includes/WebStart.php(89): require_once(string)
#21 /srv/mediawiki/php-1.36.0-wmf.10/api.php(43): require(string)
#22 /srv/mediawiki/w/api.php(3): require(string)
#23 {main}
Stack Trace
#0 /srv/mediawiki/php-1.36.0-wmf.10/includes/user/User.php(2024): User->load()
#1 /srv/mediawiki/php-1.36.0-wmf.10/includes/user/User.php(2963): User->getId()
#2 /srv/mediawiki/php-1.36.0-wmf.10/includes/user/User.php(2979): User->isRegistered()
#3 /srv/mediawiki/php-1.36.0-wmf.10/extensions/UniversalLanguageSelector/includes/UniversalLanguageSelectorHooks.php(329): User->isAnon()
#4 /srv/mediawiki/php-1.36.0-wmf.10/includes/HookContainer/HookContainer.php(331): UniversalLanguageSelectorHooks::getLanguage(User, string, RequestContext)
#5 /srv/mediawiki/php-1.36.0-wmf.10/includes/HookContainer/HookContainer.php(138): MediaWiki\HookContainer\HookContainer->callLegacyHook(string, array, array, array)
#6 /srv/mediawiki/php-1.36.0-wmf.10/includes/HookContainer/HookRunner.php(4261): MediaWiki\HookContainer\HookContainer->run(string, array)
#7 /srv/mediawiki/php-1.36.0-wmf.10/includes/context/RequestContext.php(367): MediaWiki\HookContainer\HookRunner->onUserGetLanguageObject(User, string, RequestContext)
#8 /srv/mediawiki/php-1.36.0-wmf.10/includes/language/Message.php(391): RequestContext->getLanguage()
#9 /srv/mediawiki/php-1.36.0-wmf.10/includes/language/Message.php(1291): Message->getLanguage()
#10 /srv/mediawiki/php-1.36.0-wmf.10/includes/language/Message.php(849): Message->fetchMessage()
#11 /srv/mediawiki/php-1.36.0-wmf.10/includes/language/Message.php(941): Message->toString(string)
#12 /srv/mediawiki/php-1.36.0-wmf.10/includes/Title.php(660): Message->text()
#13 /srv/mediawiki/php-1.36.0-wmf.10/extensions/BetaFeatures/includes/BetaFeaturesHooks.php(93): Title::newMainPage()
#14 /srv/mediawiki/php-1.36.0-wmf.10/includes/HookContainer/HookContainer.php(331): BetaFeaturesHooks::updateUserCounts(User, array, array)
#15 /srv/mediawiki/php-1.36.0-wmf.10/includes/HookContainer/HookContainer.php(138): MediaWiki\HookContainer\HookContainer->callLegacyHook(string, array, array, array)
#16 /srv/mediawiki/php-1.36.0-wmf.10/includes/HookContainer/HookRunner.php(4450): MediaWiki\HookContainer\HookContainer->run(string, array)
#17 /srv/mediawiki/php-1.36.0-wmf.10/includes/user/UserOptionsManager.php(397): MediaWiki\HookContainer\HookRunner->onUserSaveOptions(User, array, array)
#18 /srv/mediawiki/php-1.36.0-wmf.10/includes/user/User.php(3401): MediaWiki\User\UserOptionsManager->saveOptions(User)
#19 /srv/mediawiki/php-1.36.0-wmf.10/includes/auth/AuthManager.php(1767): User->saveSettings()
#20 /srv/mediawiki/php-1.36.0-wmf.10/includes/Setup.php(812): MediaWiki\Auth\AuthManager->autoCreateUser(User, string, boolean)
#21 /srv/mediawiki/php-1.36.0-wmf.10/includes/WebStart.php(89): require_once(string)
#22 /srv/mediawiki/php-1.36.0-wmf.10/api.php(43): require(string)
#23 /srv/mediawiki/w/api.php(3): require(string)
#24 {main}
Stack Trace
#0 /srv/mediawiki/php-1.36.0-wmf.10/includes/user/User.php(2049): User->load()
#1 /srv/mediawiki/php-1.36.0-wmf.10/includes/user/UserOptionsManager.php(587): User->getName()
#2 /srv/mediawiki/php-1.36.0-wmf.10/includes/user/UserOptionsManager.php(490): MediaWiki\User\UserOptionsManager->getCacheKey(User)
#3 /srv/mediawiki/php-1.36.0-wmf.10/includes/user/UserOptionsManager.php(138): MediaWiki\User\UserOptionsManager->loadUserOptions(User, integer)
#4 /srv/mediawiki/php-1.36.0-wmf.10/includes/user/User.php(2564): MediaWiki\User\UserOptionsManager->getOption(User, string, NULL, boolean)
#5 /srv/mediawiki/php-1.36.0-wmf.10/includes/context/RequestContext.php(351): User->getOption(string)
#6 /srv/mediawiki/php-1.36.0-wmf.10/includes/language/Message.php(391): RequestContext->getLanguage()
#7 /srv/mediawiki/php-1.36.0-wmf.10/includes/language/Message.php(1291): Message->getLanguage()
#8 /srv/mediawiki/php-1.36.0-wmf.10/includes/language/Message.php(849): Message->fetchMessage()
#9 /srv/mediawiki/php-1.36.0-wmf.10/includes/language/Message.php(941): Message->toString(string)
#10 /srv/mediawiki/php-1.36.0-wmf.10/includes/Title.php(660): Message->text()
#11 /srv/mediawiki/php-1.36.0-wmf.10/extensions/BetaFeatures/includes/BetaFeaturesHooks.php(93): Title::newMainPage()
#12 /srv/mediawiki/php-1.36.0-wmf.10/includes/HookContainer/HookContainer.php(331): BetaFeaturesHooks::updateUserCounts(User, array, array)
#13 /srv/mediawiki/php-1.36.0-wmf.10/includes/HookContainer/HookContainer.php(138): MediaWiki\HookContainer\HookContainer->callLegacyHook(string, array, array, array)
#14 /srv/mediawiki/php-1.36.0-wmf.10/includes/HookContainer/HookRunner.php(4450): MediaWiki\HookContainer\HookContainer->run(string, array)
#15 /srv/mediawiki/php-1.36.0-wmf.10/includes/user/UserOptionsManager.php(397): MediaWiki\HookContainer\HookRunner->onUserSaveOptions(User, array, array)
#16 /srv/mediawiki/php-1.36.0-wmf.10/includes/user/User.php(3401): MediaWiki\User\UserOptionsManager->saveOptions(User)
#17 /srv/mediawiki/php-1.36.0-wmf.10/includes/auth/AuthManager.php(1767): User->saveSettings()
#18 /srv/mediawiki/php-1.36.0-wmf.10/includes/Setup.php(812): MediaWiki\Auth\AuthManager->autoCreateUser(User, string, boolean)
#19 /srv/mediawiki/php-1.36.0-wmf.10/includes/WebStart.php(89): require_once(string)
#20 /srv/mediawiki/php-1.36.0-wmf.10/api.php(43): require(string)
#21 /srv/mediawiki/w/api.php(3): require(string)
#22 {main}
Impact
  1. Notes

Details

Request ID
05181ad3-a395-4aab-8163-5ff8b05ea120

Event Timeline

Looks like we can skip passing the Title by using a GenericParameterJob. Introduced in 1.34.0 via fc5d51f12936edb4c7d067e298b5ec3a7c09a8fa

That does solve the solve the root cause of Message trying to load a user while in setup but would at least address that specific BetaFeatures issue.

Change 633160 had a related patch set uploaded (by Hashar; owner: Hashar):
[mediawiki/extensions/BetaFeatures@master] UserCountsJob does not need a Title

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

Low priority, it seems harmless it is just a source of log spam in the session logging bucket.

Change 633160 merged by jenkins-bot:
[mediawiki/extensions/BetaFeatures@master] UserCountsJob does not need a Title

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

Pending confirmation in production.

Looked into Logstash with channel:"session" AND exception.trace:BetaFeatures AND normalized_message.raw:"User::loadFromSession called before the end of Setup.php" and it is gone:

betafeatures_load_from_session.png (219×715 px, 13 KB)

There are still other code paths triggering the same log, but this task was just for BetaFeatures which was the primary source of logs.