Page MenuHomePhabricator

OAuth throws "duplicate key" at some occasions
Closed, DeclinedPublicPRODUCTION ERROR

Description

Error

Request ID: XWBpyQpAICAAAFBj-OgAAACC
Request URL: https://meta.m.wikimedia.org/wiki/Special:OAuth/authorize?oauth_token=(redacted)&oauth_consumer_key=e4813d75b345691996560c791d0640b0

message
MediaWiki\Extensions\OAuth\MWOAuthDAO::save	10.64.48.15	1062	Duplicate entry 'redacted' for key 'oaac_user_consumer_wiki' (10.64.48.15)	INSERT  INTO `oauth_accepted_consumer` (oaac_wiki,oaac_user_id,oaac_consumer_id,oaac_access_token,oaac_access_secret,oaac_grants,oaac_accepted) VALUES (redacted)
trace
#0 /srv/mediawiki/php-1.34.0-wmf.19/includes/libs/rdbms/database/Database.php(1564): Wikimedia\Rdbms\Database->getQueryExceptionAndLog('Duplicate entry...', 1062, 'INSERT  INTO `o...', 'MediaWiki\\Exten...')
#1 /srv/mediawiki/php-1.34.0-wmf.19/includes/libs/rdbms/database/Database.php(1153): Wikimedia\Rdbms\Database->reportQueryError('Duplicate entry...', 1062, 'INSERT  INTO `o...', 'MediaWiki\\Exten...', false)
#2 /srv/mediawiki/php-1.34.0-wmf.19/includes/libs/rdbms/database/Database.php(2129): Wikimedia\Rdbms\Database->query('INSERT  INTO `o...', 'MediaWiki\\Exten...')
#3 /srv/mediawiki/php-1.34.0-wmf.19/includes/libs/rdbms/database/DBConnRef.php(68): Wikimedia\Rdbms\Database->insert('`oauth_accepted...', Array, 'MediaWiki\\Exten...')
#4 /srv/mediawiki/php-1.34.0-wmf.19/includes/libs/rdbms/database/DBConnRef.php(371): Wikimedia\Rdbms\DBConnRef->__call('insert', Array)
#5 /srv/mediawiki/php-1.34.0-wmf.19/extensions/OAuth/includes/backend/MWOAuthDAO.php(192): Wikimedia\Rdbms\DBConnRef->insert('oauth_accepted_...', Array, 'MediaWiki\\Exten...')
#6 /srv/mediawiki/php-1.34.0-wmf.19/extensions/OAuth/includes/backend/MWOAuthServer.php(409): MediaWiki\Extensions\OAuth\MWOAuthDAO->save(Object(Wikimedia\Rdbms\DBConnRef))
#7 /srv/mediawiki/php-1.34.0-wmf.19/extensions/OAuth/includes/control/MWOAuthConsumerAcceptanceSubmitControl.php(105): MediaWiki\Extensions\OAuth\MWOAuthServer->authorize('e4813d75b345691...', 'aaf17d381d62dab...', Object(User), false)
#8 /srv/mediawiki/php-1.34.0-wmf.19/extensions/OAuth/includes/control/MWOAuthSubmitControl.php(74): MediaWiki\Extensions\OAuth\MWOAuthConsumerAcceptanceSubmitControl->processAction('accept')
#9 /srv/mediawiki/php-1.34.0-wmf.19/extensions/OAuth/includes/frontend/specialpages/SpecialMWOAuth.php(424): MediaWiki\Extensions\OAuth\MWOAuthSubmitControl->submit()
#10 /srv/mediawiki/php-1.34.0-wmf.19/includes/htmlform/HTMLForm.php(689): MediaWiki\Extensions\OAuth\SpecialMWOAuth->MediaWiki\Extensions\OAuth\{closure}(Array, Object(HTMLForm))
#11 /srv/mediawiki/php-1.34.0-wmf.19/includes/htmlform/HTMLForm.php(581): HTMLForm->trySubmit()
#12 /srv/mediawiki/php-1.34.0-wmf.19/includes/htmlform/HTMLForm.php(596): HTMLForm->tryAuthorizedSubmit()
#13 /srv/mediawiki/php-1.34.0-wmf.19/extensions/OAuth/includes/frontend/specialpages/SpecialMWOAuth.php(482): HTMLForm->show()
#14 /srv/mediawiki/php-1.34.0-wmf.19/extensions/OAuth/includes/frontend/specialpages/SpecialMWOAuth.php(106): MediaWiki\Extensions\OAuth\SpecialMWOAuth->handleAuthorizationForm('aaf17d381d62dab...', 'e4813d75b345691...', false)
#15 /srv/mediawiki/php-1.34.0-wmf.19/includes/specialpage/SpecialPage.php(571): MediaWiki\Extensions\OAuth\SpecialMWOAuth->execute('authorize')
#16 /srv/mediawiki/php-1.34.0-wmf.19/includes/specialpage/SpecialPageFactory.php(582): SpecialPage->run('authorize')
#17 /srv/mediawiki/php-1.34.0-wmf.19/includes/MediaWiki.php(296): MediaWiki\Special\SpecialPageFactory->executePath(Object(Title), Object(RequestContext))
#18 /srv/mediawiki/php-1.34.0-wmf.19/includes/MediaWiki.php(892): MediaWiki->performRequest()
#19 /srv/mediawiki/php-1.34.0-wmf.19/includes/MediaWiki.php(523): MediaWiki->main()
#20 /srv/mediawiki/php-1.34.0-wmf.19/index.php(42): MediaWiki->run()
#21 /srv/mediawiki/w/index.php(3): require('/srv/mediawiki/...')
Impact

Unknown.

Notes

@Janbery encountered this error after logging to https://tools.wmflabs.org/ipcheck/. He was successful on second try.

Event Timeline

Tgr triaged this task as Low priority.Aug 25 2019, 10:15 PM
Tgr subscribed.

This would presumably happen due to replication lag (maybe when you double-submit, although in theory OAuth has a nonce to prevent that), since MWOAuthServer::getCurrentAuthorization uses the read connection. Should be pretty rare and at worst forces the user to repeat the authorization.

mmodell changed the subtype of this task from "Task" to "Production Error".Aug 28 2019, 11:06 PM

@Tgr This currently renders a fatal error page. If it's normal for the row to sometimes already exist, then perhaps MWOAuthDAO::save() or its caller should catch the exception and respond with something other than HTTP 5xx which raises error levels for prod traffic.

Looking more closely, it seems odd to read from a replica when informing a write. If this code is already going to use the master DB for a write, it should be reading from there instead in the same transaction. Also, I don't know about the underlying needs of this particular query, but if it's just about ensuring a row exists, upsert() might be appropiate here.

No longer seen in the last 30 days.