Page MenuHomePhabricator

createaccount API fails intermittently when performing frequent queries
Closed, DuplicatePublic

Description

This was uncovered as part of the API integration testing initiative. The output of the test is as follows:

AssertionError: User "<anon>": Action "createaccount" returned error code "internal_api_error_DBQueryError": [e157f2f8b7882298c9335dfa] Exception caught: A database query error has occurred. This may indicate a bug in the software.!

This appears to happen "sometimes" when creating multiple user accounts in quick succession/in parallel.

[exception] [86a30c127f24cc294a52e10b] /mediawiki/api.php   Wikimedia\Rdbms\DBQueryError from line 1596 of /var/www/mediawiki/includes/libs/rdbms/database/Database.php: A database query error has occurred. Did you forget to run your application's database schema updater after upgrading? 
Query: INSERT IGNORE INTO `user` (user_name,user_password,user_newpassword,user_email,user_email_authenticated,user_real_name,user_token,user_registration,user_editcount,user_touched) VALUES ('Fiona rP1u6F7lZW','','','',NULL,'','6df48babcce9b00c103ba4518fedb8b8','20190814204515','0','20190814204515')
Function: User::addToDatabase
Error: 1213 Deadlock found when trying to get lock; try restarting transaction (db-master)
#0 /var/www/mediawiki/includes/libs/rdbms/database/Database.php(1567): Wikimedia\Rdbms\Database->getQueryExceptionAndLog(string, integer, string, string)
#1 /var/www/mediawiki/includes/libs/rdbms/database/Database.php(1156): Wikimedia\Rdbms\Database->reportQueryError(string, integer, string, string, boolean)
#2 /var/www/mediawiki/includes/libs/rdbms/database/Database.php(2132): Wikimedia\Rdbms\Database->query(string, string)
#3 /var/www/mediawiki/includes/user/User.php(4186): Wikimedia\Rdbms\Database->insert(string, array, string, string)
#4 /var/www/mediawiki/includes/libs/rdbms/database/Database.php(3956): User->{closure}(Wikimedia\Rdbms\DatabaseMysqli, string)
#5 /var/www/mediawiki/includes/libs/rdbms/database/DBConnRef.php(68): Wikimedia\Rdbms\Database->doAtomicSection(string, Closure)
#6 /var/www/mediawiki/includes/libs/rdbms/database/DBConnRef.php(630): Wikimedia\Rdbms\DBConnRef->__call(string, array)
#7 /var/www/mediawiki/includes/user/User.php(4212): Wikimedia\Rdbms\DBConnRef->doAtomicSection(string, Closure)
#8 /var/www/mediawiki/includes/auth/AuthManager.php(1423): User->addToDatabase()
#9 /var/www/mediawiki/includes/auth/AuthManager.php(1150): MediaWiki\Auth\AuthManager->continueAccountCreation(array)
#10 /var/www/mediawiki/includes/api/ApiAMCreateAccount.php(93): MediaWiki\Auth\AuthManager->beginAccountCreation(User, array, string)
#11 /var/www/mediawiki/includes/api/ApiMain.php(1589): ApiAMCreateAccount->execute()
#12 /var/www/mediawiki/includes/api/ApiMain.php(533): ApiMain->executeAction()
#13 /var/www/mediawiki/includes/api/ApiMain.php(504): ApiMain->executeActionWithErrorHandling()
#14 /var/www/mediawiki/api.php(86): ApiMain->execute()
#15 {main}

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald TranscriptWed, Aug 14, 7:36 PM
CCicalese_WMF triaged this task as Normal priority.Wed, Aug 14, 7:37 PM
daniel updated the task description. (Show Details)Wed, Aug 14, 8:19 PM
daniel updated the task description. (Show Details)
daniel added subscribers: Anomie, daniel.EditedWed, Aug 14, 9:03 PM

@Anomie Can you help me understand this? This fatal error is pretty easy to trigger by hitting action=createaccount repeatedly. It also seems to happen quickly, so no timeout (or a very quick one). Any idea how to fix this? For the API tests, we frequently need to create several user accounts in a row.

Probably a duplicate of T199393: Reproducible deadlock in User::addToDatabase() when api.php?action=createaccount is called simultaneously by several users. See T199393#4420174 in particular, and also T222402#5167444 which explains the gap lock deadlock a little better.

Indeed. Thanks @Anomie! Now the question is - how can we fix that?...