Page MenuHomePhabricator

Exception: User::addToDatabase: hit a key conflict attempting to insert a user row, but then it doesn't exist when we select it!
Closed, ResolvedPublic

Description

Comes up pretty often in the logs, even on action=raw, CentralNotice and api.php requests.

A few samples:

2012-10-31 22:03:32 mw43 metawiki: [752b3943] /w/index.php?title=MediaWiki:Wikiminiatlas.js&action=raw&ctype=text/javascript&smaxage=21600&maxage=86400

Exception from line 3079 of /usr/local/apache/common-local/php-1.21wmf3/includes/User.php: User::addToDatabase: hit a key conflict attempting to insert a user row, but then it doesn't exist when we select it!
#0 /usr/local/apache/common-local/php-1.21wmf3/extensions/CentralAuth/CentralAuthHooks.php(568): User->addToDatabase()
#1 /usr/local/apache/common-local/php-1.21wmf3/extensions/CentralAuth/CentralAuthHooks.php(276): CentralAuthHooks::attemptAddUser(Object(User), 'W1k1n66m')
#2 [internal function]: CentralAuthHooks::onUserLoadFromSession(Object(User), NULL)
#3 /usr/local/apache/common-local/php-1.21wmf3/includes/Hooks.php(253): call_user_func_array('CentralAuthHook...', Array)

2012-10-31 22:05:29 mw52 metawiki: [3b339d91] /wiki/Special:BannerRandom?userlang=es&sitename=Wikimedia+Commons&project=commons&anonymous=false&bucket=0&country=ES&slot=10

Exception from line 3079 of /usr/local/apache/common-local/php-1.21wmf3/includes/User.php: User::addToDatabase: hit a key conflict attempting to insert a user row, but then it doesn't exist when we select it!
#0 /usr/local/apache/common-local/php-1.21wmf3/extensions/CentralAuth/CentralAuthHooks.php(568): User->addToDatabase()
#1 /usr/local/apache/common-local/php-1.21wmf3/extensions/CentralAuth/CentralAuthHooks.php(276): CentralAuthHooks::attemptAddUser(Object(User), 'Cotillasnosotro...')
#2 [internal function]: CentralAuthHooks::onUserLoadFromSession(Object(User), NULL)
#3 /usr/local/apache/common-local/php-1.21wmf3/includes/Hooks.php(253): call_user_func_array('CentralAuthHook...', Array)

2012-10-31 22:10:43 srv203 metawiki: [453483ac] /w/index.php?title=MediaWiki:OSM.js&action=raw&ctype=text/javascript&smaxage=21600&maxage=86400

Exception from line 3079 of /usr/local/apache/common-local/php-1.21wmf3/includes/User.php: User::addToDatabase: hit a key conflict attempting to insert a user row, but then it doesn't exist when we select it!
#0 /usr/local/apache/common-local/php-1.21wmf3/extensions/CentralAuth/CentralAuthHooks.php(568): User->addToDatabase()
#1 /usr/local/apache/common-local/php-1.21wmf3/extensions/CentralAuth/CentralAuthHooks.php(276): CentralAuthHooks::attemptAddUser(Object(User), 'Aldha')
#2 [internal function]: CentralAuthHooks::onUserLoadFromSession(Object(User), NULL)
#3 /usr/local/apache/common-local/php-1.21wmf3/includes/Hooks.php(253): call_user_func_array('CentralAuthHook...', Array)

2012-10-31 22:18:02 srv301 huwiki: [7731f9cf] /w/api.php?action=query&titles...p=size&format=json

Exception from line 3072 of /usr/local/apache/common-local/php-1.21wmf2/includes/User.php: User::addToDatabase: hit a key conflict attempting to insert a user row, but then it doesn't exist when we select it!
#0 /usr/local/apache/common-local/php-1.21wmf2/extensions/CentralAuth/CentralAuthHooks.php(568): User->addToDatabase()
#1 /usr/local/apache/common-local/php-1.21wmf2/extensions/CentralAuth/CentralAuthHooks.php(276): CentralAuthHooks::attemptAddUser(Object(User), 'Blake13441')
#2 [internal function]: CentralAuthHooks::onUserLoadFromSession(Object(User), NULL)
#3 /usr/local/apache/common-local/php-1.21wmf2/includes/Hooks.php(253): call_user_func_array('CentralAuthHook...', Array)

2012-10-31 22:24:47 mw21 metawiki: [63064713] /w/index.php?title=MediaWiki:OSM.js&action=raw&ctype=text/javascript&smaxage=21600&maxage=86400

Exception from line 3079 of /usr/local/apache/common-local/php-1.21wmf3/includes/User.php: User::addToDatabase: hit a key conflict attempting to insert a user row, but then it doesn't exist when we select it!
#0 /usr/local/apache/common-local/php-1.21wmf3/extensions/CentralAuth/CentralAuthHooks.php(568): User->addToDatabase()
#1 /usr/local/apache/common-local/php-1.21wmf3/extensions/CentralAuth/CentralAuthHooks.php(276): CentralAuthHooks::attemptAddUser(Object(User), 'JorgebossGL')
#2 [internal function]: CentralAuthHooks::onUserLoadFromSession(Object(User), NULL)
#3 /usr/local/apache/common-local/php-1.21wmf3/includes/Hooks.php(253): call_user_func_array('CentralAuthHook...', Array)

2012-10-31 22:31:46 srv241 commonswiki: [36936ded] /wiki/Category:Solar_eclipse

Exception from line 3079 of /usr/local/apache/common-local/php-1.21wmf3/includes/User.php: User::addToDatabase: hit a key conflict attempting to insert a user row, but then it doesn't exist when we select it!
#0 /usr/local/apache/common-local/php-1.21wmf3/extensions/CentralAuth/CentralAuthHooks.php(568): User->addToDatabase()
#1 /usr/local/apache/common-local/php-1.21wmf3/extensions/CentralAuth/CentralAuthHooks.php(276): CentralAuthHooks::attemptAddUser(Object(User), 'Mvemjsunp8')
#2 [internal function]: CentralAuthHooks::onUserLoadFromSession(Object(User), NULL)
#3 /usr/local/apache/common-local/php-1.21wmf3/includes/Hooks.php(253): call_user_func_array('CentralAuthHook...', Array)

2012-10-31 22:36:28 mw39 metawiki: [32ca71d8] /wiki/Special:BannerRandom?userlang=da&sitename=Wikipedia&project=wikipedia&anonymous=false&bucket=0&country=DK&slot=30

Exception from line 3079 of /usr/local/apache/common-local/php-1.21wmf3/includes/User.php: User::addToDatabase: hit a key conflict attempting to insert a user row, but then it doesn't exist when we select it!
#0 /usr/local/apache/common-local/php-1.21wmf3/extensions/CentralAuth/CentralAuthHooks.php(568): User->addToDatabase()
#1 /usr/local/apache/common-local/php-1.21wmf3/extensions/CentralAuth/CentralAuthHooks.php(276): CentralAuthHooks::attemptAddUser(Object(User), 'Djbenne')
#2 [internal function]: CentralAuthHooks::onUserLoadFromSession(Object(User), NULL)
#3 /usr/local/apache/common-local/php-1.21wmf3/includes/Hooks.php(253): call_user_func_array('CentralAuthHook...', Array)


Version: master
Severity: normal

Details

Reference
bz41609

Event Timeline

bzimport raised the priority of this task from to High.Nov 22 2014, 1:00 AM
bzimport set Reference to bz41609.
Krinkle created this task.Oct 31 2012, 11:38 PM

mwalker wrote:

*** Bug 41659 has been marked as a duplicate of this bug. ***

Chris, could you take a look at this one?

I'm going to guess the race condition that Tim's patch (I1f6ef5e6319bfe692fb82a3fa50dc66c9fde8f15) addresses is still happening, and in some cases it's causing this weird situation to occur.

It would be nice to know the value of $this->mId when the exception happens. Anyone mind if we add that to the exception message?

aaron added a comment.Jun 19 2013, 9:12 PM

This is far less frequent after the CentralAuth fix by Marius to check if names are valid before doing the INSERT (the IGNORE caused silent truncation, so the insert affected a row but the SELECT later failed).

This still sometimes occurs due to INSERT INGORE semantics mixing very awkwardly with REPEATABLE READ isolation.

aaron added a comment.Jun 19 2013, 9:14 PM

Typical error:

2013-06-19 15:42:38 mw1018 metawiki: [935537c9] /wiki/Help:Unified_login/ru Exception from line 3303 of /usr/local/apache/common-local/php-1.22wmf7/includes/User.php: User::addToDatabase: hit a key conflict attempting to insert user 'Ni-kasyanov' row, but it was not present in select!
#0 /usr/local/apache/common-local/php-1.22wmf7/extensions/CentralAuth/CentralAuthHooks.php(824): User->addToDatabase()
#1 /usr/local/apache/common-local/php-1.22wmf7/extensions/CentralAuth/CentralAuthHooks.php(524): CentralAuthHooks::attemptAddUser(Object(User))
#2 [internal function]: CentralAuthHooks::onUserLoadFromSession(Object(User), NULL)
#3 /usr/local/apache/common-local/php-1.22wmf7/includes/Hooks.php(196): call_user_func_array('CentralAuthHook...', Array)
#4 /usr/local/apache/common-local/php-1.22wmf7/includes/GlobalFunctions.php(3834): Hooks::run('UserLoadFromSes...', Array)
#5 /usr/local/apache/common-local/php-1.22wmf7/includes/User.php(929): wfRunHooks('UserLoadFromSes...', Array)
#6 /usr/local/apache/common-local/php-1.22wmf7/includes/User.php(291): User->loadFromSession()
#7 /usr/local/apache/common-local/php-1.22wmf7/includes/User.php(4400): User->load()
#8 /usr/local/apache/common-local/php-1.22wmf7/includes/User.php(2278): User->loadOptions()
#9 /usr/local/apache/common-local/php-1.22wmf7/includes/context/RequestContext.php(296): User->getOption('language')
#10 /usr/local/apache/common-local/php-1.22wmf7/includes/Message.php(360): RequestContext->getLanguage()
#11 /usr/local/apache/common-local/php-1.22wmf7/includes/context/RequestContext.php(377): Message->setContext(Object(RequestContext))
#12 [internal function]: RequestContext->msg('pagetitle')
#13 /usr/local/apache/common-local/php-1.22wmf7/includes/context/ContextSource.php(165): call_user_func_array(Array, Array)
#14 /usr/local/apache/common-local/php-1.22wmf7/includes/OutputPage.php(889): ContextSource->msg('pagetitle')
#15 /usr/local/apache/common-local/php-1.22wmf7/includes/Article.php(555): OutputPage->setPageTitle('Help:Unified lo...')
#16 /usr/local/apache/common-local/php-1.22wmf7/includes/actions/ViewAction.php(44): Article->view()
#17 /usr/local/apache/common-local/php-1.22wmf7/includes/Wiki.php(439): ViewAction->show()
#18 /usr/local/apache/common-local/php-1.22wmf7/includes/Wiki.php(305): MediaWiki->performAction(Object(Article), Object(Title))
#19 /usr/local/apache/common-local/php-1.22wmf7/includes/Wiki.php(565): MediaWiki->performRequest()
#20 /usr/local/apache/common-local/php-1.22wmf7/includes/Wiki.php(458): MediaWiki->main()
#21 /usr/local/apache/common-local/php-1.22wmf7/index.php(55): MediaWiki->run()
#22 /usr/local/apache/common-local/w/index.php(3): require('/usr/local/apac...')
#23 {main}

jdelpozo wrote:

Thank you very much, Aaron.

I have tried that patch (https://gerrit.wikimedia.org/r/#/c/69587/), and I am still getting these messages:

User::addToDatabase: hit a key conflict attempting to insert a user row, but then it doesn't exist when we select it!
Backtrace:
#0 /home/mediawiki_SBM/includes/specials/SpecialUserlogin.php(468): User->addToDatabase()
#1 /home/mediawiki_SBM/includes/specials/SpecialUserlogin.php(453): LoginForm->initUser(Object(User), false)
#2 /home/mediawiki_SBM/includes/specials/SpecialUserlogin.php(236): LoginForm->addNewAccountInternal()
#3 /home/mediawiki_SBM/includes/specials/SpecialUserlogin.php(178): LoginForm->addNewAccount()
#4 /home/mediawiki_SBM/includes/SpecialPage.php(613): LoginForm->execute(NULL)
#5 /home/mediawiki_SBM/includes/SpecialPageFactory.php(487): SpecialPage->run(NULL)
#6 /home/mediawiki_SBM/includes/Wiki.php(291): SpecialPageFactory::executePath(Object(Title), Object(RequestContext))
#7 /home/mediawiki_SBM/includes/Wiki.php(565): MediaWiki->performRequest()
#8 /home/mediawiki_SBM/includes/Wiki.php(458): MediaWiki->main()
#9 /home/mediawiki_SBM/index.php(59): MediaWiki->run()
#10 {main}

Fenhl reopened this task as Open.Jul 10 2015, 5:04 PM
Fenhl added a subscriber: Fenhl.

Receiving a similar error in MediaWiki 1.25.1:

[05dbae81] /index.php?title=Special:UserLogin&action=submitlogin&type=signup MWException from line 3828 of /var/www/wiki.wurstmineberg.de/includes/User.php: User::addToDatabase: hit a key conflict attempting to insert user 'BenemitC' row, but it was not present in select!

Receiving a similar error in MediaWiki 1.25.1:
[05dbae81] /index.php?title=Special:UserLogin&action=submitlogin&type=signup MWException from line 3828 of /var/www/wiki.wurstmineberg.de/includes/User.php: User::addToDatabase: hit a key conflict attempting to insert user 'BenemitC' row, but it was not present in select!

Are you using CentralAuth?

Fenhl added a comment.Jul 10 2015, 8:21 PM

Are you using CentralAuth?

No, but we are using OpenID

Legoktm closed this task as Resolved.Jul 10 2015, 8:21 PM

Are you using CentralAuth?

No, but we are using OpenID

Please open a different bug then.