Page MenuHomePhabricator

Babel autocreates category and system user on GET
Closed, ResolvedPublic

Description

Babel seems to autocreate a category sometimes, and to make the edit for that, it also needs to ensure its system user exists, which is also autocreated.

All this can be on GET from api.php?action=parse. And even in cases where an autocreation isn't needed (i.e. the system user already exists), User::newSystemUser() still opens a master connection.

Expectation (masterConns <= 0) by ApiMain::setRequestExpectations not met:
[connect to 10.64.16.30 (metawiki)]
#0 /srv/mediawiki/php-1.29.0-wmf.6/includes/libs/rdbms/TransactionProfiler.php(160): TransactionProfiler->reportExpectationViolated()
#1 /srv/mediawiki/php-1.29.0-wmf.6/includes/libs/rdbms/loadbalancer/LoadBalancer.php(587): TransactionProfiler->recordConnection()
#2 /srv/mediawiki/php-1.29.0-wmf.6/includes/GlobalFunctions.php(3077): LoadBalancer->getConnection()
#3 /srv/mediawiki/php-1.29.0-wmf.6/includes/user/User.php(671): wfGetDB()
#4 /srv/mediawiki/php-1.29.0-wmf.6/extensions/Babel/BabelAutoCreate.class.php(96): User::newSystemUser()
#5 /srv/mediawiki/php-1.29.0-wmf.6/extensions/Babel/BabelAutoCreate.class.php(54): BabelAutoCreate::user()
#6 /srv/mediawiki/php-1.29.0-wmf.6/extensions/Babel/BabelBox/LanguageBabelBox.php(183): BabelAutoCreate::create()
#7 /srv/mediawiki/php-1.29.0-wmf.6/extensions/Babel/Babel.class.php(192): MediaWiki\Babel\BabelBox\LanguageBabelBox->getCategories()
#8 /srv/mediawiki/php-1.29.0-wmf.6/extensions/Babel/Babel.class.php(119): Babel::mGenerateContent()
#9 /srv/mediawiki/php-1.29.0-wmf.6/extensions/Babel/Babel.class.php(47): Babel::mGenerateContentTower()
#10 /srv/mediawiki/php-1.29.0-wmf.6/includes/parser/Parser.php(3379): Babel::Render()
#11 /srv/mediawiki/php-1.29.0-wmf.6/includes/parser/Parser.php(3103): Parser->callParserFunction()
#12 /srv/mediawiki/php-1.29.0-wmf.6/includes/parser/Preprocessor_Hash.php(1015): Parser->braceSubstitution()
#13 /srv/mediawiki/php-1.29.0-wmf.6/includes/parser/Preprocessor_Hash.php(1448): PPFrame_Hash->expand()
#14 /srv/mediawiki/php-1.29.0-wmf.6/includes/parser/Parser.php(3253): PPTemplateFrame_Hash->cachedExpand()
#15 /srv/mediawiki/php-1.29.0-wmf.6/includes/parser/Preprocessor_Hash.php(1015): Parser->braceSubstitution()
#16 /srv/mediawiki/php-1.29.0-wmf.6/includes/parser/Parser.php(2917): PPFrame_Hash->expand()
#17 /srv/mediawiki/php-1.29.0-wmf.6/includes/parser/Parser.php(1265): Parser->replaceVariables()
#18 /srv/mediawiki/php-1.29.0-wmf.6/includes/parser/Parser.php(441): Parser->internalParse()
#19 /srv/mediawiki/php-1.29.0-wmf.6/includes/StubObject.php(113): Parser->parse()
#20 /srv/mediawiki/php-1.29.0-wmf.6/includes/StubObject.php(139): StubObject->_call()
#21 /srv/mediawiki/php-1.29.0-wmf.6/includes/content/WikitextContent.php(330): StubObject->__call()
#22 /srv/mediawiki/php-1.29.0-wmf.6/includes/content/AbstractContent.php(497): WikitextContent->fillParserOutput()
#23 /srv/mediawiki/php-1.29.0-wmf.6/includes/api/ApiParse.php(274): AbstractContent->getParserOutput()
#24 /srv/mediawiki/php-1.29.0-wmf.6/includes/api/ApiMain.php(1532): ApiParse->execute()
#25 /srv/mediawiki/php-1.29.0-wmf.6/includes/api/ApiMain.php(541): ApiMain->executeAction()
#26 /srv/mediawiki/php-1.29.0-wmf.6/includes/api/ApiMain.php(512): ApiMain->executeActionWithErrorHandling()
#27 /srv/mediawiki/php-1.29.0-wmf.6/api.php(83): ApiMain->execute()
#28 /srv/mediawiki/w/api.php(3): include()
#29 {main}

Event Timeline

I think these auto-creations can just be deferred. To be honest I thought they already were...

Change 413093 had a related patch set uploaded (by Tim Starling; owner: Tim Starling):
[mediawiki/extensions/Babel@master] Defer Babel category creation

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

Krinkle renamed this task from Babel autocreates user on GET to Babel autocreates category and system user on GET.Mar 17 2018, 12:38 AM
Krinkle moved this task from Tag to MediaWiki-MultiDC on the Sustainability board.
Krinkle updated the task description. (Show Details)

Change 413093 merged by jenkins-bot:
[mediawiki/extensions/Babel@master] Defer Babel category creation

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

Krinkle claimed this task.
Krinkle subscribed.

Before

Previewing an edit at https://nl.wikipedia.beta.wmflabs.org/wiki/Gebruiker:Krinkle.
Wikitext used: {{#babel: nl}}

The preview itself shows two blue category links ("Gebruiker nl" and "Gebruiker nl-M").

Babel auto-created the categories during the edit preview.

And in Logstash-beta, as expected:

Expectation (masterConns <= 0) by ApiMain::setRequestExpectations not met (actual: 1):
[connect to 10.68.23.30:3306 (nlwiki)] [..]
#3 /srv/mediawiki/php-master/includes/user/User.php(815): wfGetDB()
#4 /srv/mediawiki/php-master/extensions/Babel/includes/BabelAutoCreate.php(96): User::newSystemUser()
#5 /srv/mediawiki/php-master/extensions/Babel/includes/BabelAutoCreate.php(54): BabelAutoCreate::user()
[..]
#10 /srv/mediawiki/php-master/includes/parser/Parser.php(3426): Babel::Render()
#11 /srv/mediawiki/php-master/includes/parser/Parser.php(3127): Parser->callParserFunction()
[..]
#17 /srv/mediawiki/php-master/extensions/ParsoidBatchAPI/includes/ApiParsoidBatch.php(273): StubObject->__call()
#18 /srv/mediawiki/php-master/extensions/ParsoidBatchAPI/includes/ApiParsoidBatch.php(150): ApiParsoidBatch->preprocess()
[..]
#23 /srv/mediawiki/w/api.php(3): include()

After

Once landed and waiting a few minutes for beta-code-update and beta-scap.

Previewing an edit at https://nl.wikipedia.beta.wmflabs.org/wiki/Gebruiker:Krinkle.
Wikitext used: {{#babel: fr-1}}

The preview itself showed one blue category link and one red category link ("Gebruiker fr" and "Gebruiker fr-1").

Screen Shot 2018-03-29 at 21.43.36.png (112×932 px, 23 KB)

Seems like there is a race condition where one is created in time for the page render, but the other wasn't. Note that on this particular Beta Cluster wiki, the 2017 wikitext editor is the default which currently does not support edit stashing. As such, my rendering the preview was the first time the wikitext got sent to the server.

I imagine that in production, this is much less likely to happen with databases generally being faster, and also with edit stashing triggering this ahead of time before the first visual rendering.

Both were auto-created:

  • 06:39, 30 March 2018 (diff | hist) . . (+78)‎ . . N Categorie:Wikipedia:Gebruiker fr-1
  • 06:39, 30 March 2018 (diff | hist) . . (+79)‎ . . N Categorie:Wikipedia:Gebruiker fr ‎

And this time no entries in Logstash-beta during this time with severity warning or error.