Error
2019-05-02 10:19:29 [XMrEMQpAMDwAAGzj1h4AAAAW] mw1225 enwiki 1.34.0-wmf.1 exception ERROR: [XMrEMQpAMDwAAGzj1h4AAAAW] /w/api.php Wikimedia\Rdbms\DBQueryError Query: INSERT IGNORE INTO `page` (page_namespace,page_title,page_restrictions,page_is_redirect,page_is_new,page_random,page_touched,page_latest,page_len,page_id) VALUES ('2','Amorymeltzer/sandbox/5','','0','1','0.206380669357','20190502101929','0','0','60635647') Function: WikiPage::insertOn Error: 1213 Deadlock found when trying to get lock; try restarting transaction (10.64.32.64)
#0 /srv/mediawiki/php-1.34.0-wmf.1/includes/libs/rdbms/database/Database.php(1556): Wikimedia\Rdbms\Database->getQueryExceptionAndLog(string, integer, string, string) #1 /srv/mediawiki/php-1.34.0-wmf.1/includes/libs/rdbms/database/Database.php(1274): Wikimedia\Rdbms\Database->reportQueryError(string, integer, string, string, boolean) #2 /srv/mediawiki/php-1.34.0-wmf.1/includes/libs/rdbms/database/Database.php(2149): Wikimedia\Rdbms\Database->query(string, string) #3 /srv/mediawiki/php-1.34.0-wmf.1/includes/page/WikiPage.php(1345): Wikimedia\Rdbms\Database->insert(string, array, string, string) #4 /srv/mediawiki/php-1.34.0-wmf.1/includes/page/PageArchive.php(735): WikiPage->insertOn(Wikimedia\Rdbms\DatabaseMysqli, string) #5 /srv/mediawiki/php-1.34.0-wmf.1/includes/page/PageArchive.php(506): PageArchive->undeleteRevisions(array, boolean, string) #6 /srv/mediawiki/php-1.34.0-wmf.1/includes/api/ApiUndelete.php(74): PageArchive->undelete(array, string, NULL, boolean, User, NULL) #7 /srv/mediawiki/php-1.34.0-wmf.1/includes/api/ApiMain.php(1593): ApiUndelete->execute() #8 /srv/mediawiki/php-1.34.0-wmf.1/includes/api/ApiMain.php(531): ApiMain->executeAction() #9 /srv/mediawiki/php-1.34.0-wmf.1/includes/api/ApiMain.php(502): ApiMain->executeActionWithErrorHandling() #10 /srv/mediawiki/php-1.34.0-wmf.1/api.php(87): ApiMain->execute() #11 /srv/mediawiki/w/api.php(3): require(string) #12 {main}
Impact
User actions to restore pages or files are sometimes aborted.
There appears to be problematic lock or database query that can end up depending on another instance of itself in both directions, ergo, a deadlock.
When this happens, the user receives a generic system error page, and the spike of application crashes may end up aborting an unrelated on-going deployment or fire an Icgina monitoring alert.
Notes
(I'm not smart enough to know for a fact that this hasn't already been reported; there are a number of similar tickets, but those that are not closed appear to be somewhat different.)
Basically, attempting a bunch of action=undelete queries can result in multiple internal_api_error_DBQueryError errors, reported as Wikimedia\Rdbms\DBQueryError and a varying string like XMrEMQpAMDwAAGzj1h4AAAAW or XMtbogpAAEwAAA7kBZ0AAACO.
Sometimes it works fine, and sometimes 20%-80% of the queries fail, even after attempting them all twice. Has been going on for at least a few months, possibly much longer. This is using the batchundelete module from Twinkle on enwiki (or testwiki). The same code is used for batchdelete and doesn't result in the same errors.