Page MenuHomePhabricator

Page view fatal from LanguageConverter: "Call to a member function isSafeToLoad() on null"
Closed, ResolvedPublicPRODUCTION ERROR

Description

Error

MediaWiki version: 1.35.0-wmf.1

message
Call to a member function isSafeToLoad() on null

Impact

Some users are unable to view some pages due to this fatal error from /wiki/:… urls. Also aborted some API queries.

Only affects kk.wikipedia.org so far.

Details

Request ID
XaI6WgpAEMUAAB8m76cAAAAX
Request URL
/w/api.php?action=query&prop=revisions&format=xml&rvprop=content%7Cuser%7Cuserid%7Ccomment%7Cids%7Cflags%7Ctimestamp&titles=%D0%99%D0%B5%D1%82%D1%81%D0%B4%D0%BE%D1%80%D1%84
Stack Trace
exception.trace
#0 /languages/Language.php(4264): LanguageConverter->getPreferredVariant()
#1 /languages/classes/LanguageKk.php(409): Language->getPreferredVariant()
#2 /includes/cache/MessageCache.php(586): LanguageKk->lcfirst(string)
#3 /includes/cache/MessageCache.php(523): MessageCache->isMainCacheable(string, array)
#4 /includes/cache/MessageCache.php(397): MessageCache->loadFromDB(string, NULL)
#5 /includes/cache/MessageCache.php(320): MessageCache->loadFromDBWithLock(string, array, NULL)
#6 /includes/cache/MessageCache.php(1038): MessageCache->load(string)
#7 /includes/cache/MessageCache.php(965): MessageCache->getMsgFromNamespace(string, string)
#8 /includes/cache/MessageCache.php(935): MessageCache->getMessageForLang(LanguageKk, string, boolean, array)
#9 /includes/cache/MessageCache.php(877): MessageCache->getMessageFromFallbackChain(LanguageKk, string, boolean)
#10 /includes/language/Message.php(1297): MessageCache->get(string, boolean, LanguageKk)
#11 /includes/language/Message.php(852): Message->fetchMessage()
#12 /includes/language/Message.php(956): Message->toString(string)
#13 /includes/user/User.php(982): Message->plain()
#14 /extensions/CentralAuth/includes/session/CentralAuthSessionProvider.php(165): User::isUsableName(string)
#15 /includes/session/SessionManager.php(465): CentralAuthSessionProvider->provideSessionInfo(WebRequest)
#16 /includes/session/SessionManager.php(190): MediaWiki\Session\SessionManager->getSessionInfoForRequest(WebRequest)
#17 /includes/WebRequest.php(809): MediaWiki\Session\SessionManager->getSessionForRequest(WebRequest)
#18 /includes/session/SessionManager.php(129): WebRequest->getSession()
#19 /includes/Setup.php(803): MediaWiki\Session\SessionManager::getGlobalSession()
#20 /includes/WebStart.php(81): require_once(string)
#21 /api.php(36): require(string)
#22 /srv/mediawiki/w/api.php(3): require(string)
#23 {main}

Event Timeline

The code in question:

LanguageConverter.php
	public function getPreferredVariant() {
		global $wgUser;
		// …
		if ( $wgUser->isSafeToLoad() && $wgUser->isLoggedIn() && /* … */ ) {

... has not changed in four years. And it seems fair to expect wgUser to at least exist in general code like this. Likely has its cause elsewhere (see stack trace above).

Another problem with $wgUser not init was https://gerrit.wikimedia.org/r/#/c/mediawiki/core/+/533190/1/includes/cache/MessageCache.php
That was the case when exception needs messages

User::isUsableName is calling wfMessage for $wgReservedUsernames - so session needs messages and that maybe early in setup than the set of wgUser

LanguageKk::lcfirst is calling getPreferredVariant

Anomie added a subscriber: Anomie.

@Krinkle: I've noticed that this format you're using for these bugs leaves out the location where the actual error occurred (exception.file), in this case /srv/mediawiki/php-1.35.0-wmf.1/languages/LanguageConverter.php:171.

This doesn't seem to be a new error, I see log entries as far back as 2019-07-20T23:21:28 (XTOh@ApAIDgAAFqXt0IAAABS). All for kkwiki only. Probably they go back even earlier but the logs have expired.

It looks like this will only affect wikis with content language set to 'kk', as that's the only language that considers the variant in lcfirst(). It strikes me that that itself is probably a bug, case changing for the content language probably shouldn't depend on the variant being used for a particular request.

@Krinkle: I've noticed that this format you're using for these bugs leaves out the location where the actual error occurred (exception.file), in this case /srv/mediawiki/php-1.35.0-wmf.1/languages/LanguageConverter.php:171.

Also the wiki that the exception occurred on.

@Krinkle: I've noticed that this format you're using for these bugs leaves out the location where the actual error occurred (exception.file), in this case /srv/mediawiki/php-1.35.0-wmf.1/languages/LanguageConverter.php:171.

Yeah, this is a well-intended feature from the recently-introduced Phatality plugin for Logstash. I used to copy these manually and also prefer they remain unmodified or normalised indeed. I've already mentioned this to Mukunda last month at T233349#5520650 who has since fixed it. I'm waiting for it to be deployed.

For the originating file missing, see T237682: Phatality: Keep error message and trace closer together

Krinkle renamed this task from Call to a member function isSafeToLoad() on null to Page view fatal from LanguageConverter: "Call to a member function isSafeToLoad() on null".Nov 7 2019, 7:59 PM
Krinkle added a project: MediaWiki-Parser.
daniel triaged this task as High priority.Nov 11 2019, 8:06 PM

Change 562512 had a related patch set uploaded (by Daniel Kinzler; owner: Daniel Kinzler):
[mediawiki/core@master] LanguageConverter: don't assume $wgUser is initialized

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

Change 562512 merged by jenkins-bot:
[mediawiki/core@master] languages: Don't assume $wgUser in LanguageConverter

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

Change 580361 had a related patch set uploaded (by Krinkle; owner: Daniel Kinzler):
[mediawiki/core@wmf/1.35.0-wmf.23] languages: Don't assume $wgUser in LanguageConverter

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

Change 580361 merged by jenkins-bot:
[mediawiki/core@wmf/1.35.0-wmf.23] languages: Don't assume $wgUser in LanguageConverter

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

Mentioned in SAL (#wikimedia-operations) [2020-03-17T17:56:04Z] <ladsgroup@deploy1001> Synchronized php-1.35.0-wmf.23/languages/LanguageConverter.php: [[gerrit:580361|languages: Don't assume in LanguageConverter (T235360)]] (duration: 01m 07s)