I tried to enable concurrency for selenium tests in CampaignEvents, but the patch failed with a deadlock:
2024-12-05 14:49:58 84f8e934c16e wikidb: [d93ab29109dc05f03a23207a] /rest.php/campaignevents/v0/event_registration Wikimedia\Rdbms\DBQueryError: Error 1213: Deadlock found when trying to get lock; try restarting transaction Function: MediaWiki\Extension\CampaignEvents\Questions\EventQuestionsStore::replaceEventQuestions Query: INSERT INTO `ce_event_questions` (ceeq_event_id,ceeq_question_id) VALUES (3,1),(3,2),(3,3),(3,4),(3,5) #0 /workspace/src/includes/libs/rdbms/database/Database.php(1177): Wikimedia\Rdbms\Database->getQueryException(string, int, string, string) #1 /workspace/src/includes/libs/rdbms/database/Database.php(1151): Wikimedia\Rdbms\Database->getQueryExceptionAndLog(string, int, string, string) #2 /workspace/src/includes/libs/rdbms/database/Database.php(645): Wikimedia\Rdbms\Database->reportQueryError(string, int, string, string, bool) #3 /workspace/src/includes/libs/rdbms/database/Database.php(1471): Wikimedia\Rdbms\Database->query(Wikimedia\Rdbms\Query, string) #4 /workspace/src/includes/libs/rdbms/database/DBConnRef.php(127): Wikimedia\Rdbms\Database->insert(string, array, string, array) #5 /workspace/src/includes/libs/rdbms/database/DBConnRef.php(407): Wikimedia\Rdbms\DBConnRef->__call(string, array) #6 /workspace/src/includes/libs/rdbms/querybuilder/InsertQueryBuilder.php(343): Wikimedia\Rdbms\DBConnRef->insert(string, array, string, array) #7 /workspace/src/extensions/CampaignEvents/src/Questions/EventQuestionsStore.php(66): Wikimedia\Rdbms\InsertQueryBuilder->execute() #8 /workspace/src/extensions/CampaignEvents/src/Event/Store/EventStore.php(452): MediaWiki\Extension\CampaignEvents\Questions\EventQuestionsStore->replaceEventQuestions(int, array) #9 /workspace/src/extensions/CampaignEvents/src/Event/EditEventCommand.php(212): MediaWiki\Extension\CampaignEvents\Event\Store\EventStore->saveRegistration(MediaWiki\Extension\CampaignEvents\Event\EventRegistration) #10 /workspace/src/extensions/CampaignEvents/src/Event/EditEventCommand.php(111): MediaWiki\Extension\CampaignEvents\Event\EditEventCommand->doEditUnsafe(MediaWiki\Extension\CampaignEvents\Event\EventRegistration, MediaWiki\Extension\CampaignEvents\MWEntity\MWAuthorityProxy, array) #11 /workspace/src/extensions/CampaignEvents/src/Rest/AbstractEditEventRegistrationHandler.php(108): MediaWiki\Extension\CampaignEvents\Event\EditEventCommand->doEditIfAllowed(MediaWiki\Extension\CampaignEvents\Event\EventRegistration, MediaWiki\Extension\CampaignEvents\MWEntity\MWAuthorityProxy, array) #12 /workspace/src/includes/Rest/Module/Module.php(386): MediaWiki\Extension\CampaignEvents\Rest\AbstractEditEventRegistrationHandler->execute() #13 /workspace/src/includes/Rest/Module/Module.php(269): MediaWiki\Rest\Module\Module->executeHandler(MediaWiki\Extension\CampaignEvents\Rest\EnableEventRegistrationHandler) #14 /workspace/src/includes/Rest/Router.php(487): MediaWiki\Rest\Module\Module->execute(string, MediaWiki\Rest\RequestFromGlobals) #15 /workspace/src/includes/Rest/Router.php(446): MediaWiki\Rest\Router->doExecute(string, MediaWiki\Rest\RequestFromGlobals) #16 /workspace/src/includes/Rest/EntryPoint.php(211): MediaWiki\Rest\Router->execute(MediaWiki\Rest\RequestFromGlobals) #17 /workspace/src/includes/MediaWikiEntryPoint.php(201): MediaWiki\Rest\EntryPoint->execute() #18 /workspace/src/rest.php(39): MediaWiki\MediaWikiEntryPoint->run() #19 {main}
2024-12-05 14:49:58 213 [Note] InnoDB: Transactions deadlock detected, dumping detailed information. 2024-12-05 14:49:58 213 [Note] InnoDB: *** (1) TRANSACTION: TRANSACTION 1780, ACTIVE 0 sec inserting mysql tables in use 1, locked 1 LOCK WAIT 8 lock struct(s), heap size 1128, 4 row lock(s), undo log entries 2 MySQL thread id 214, OS thread handle 139981050271488, query id 3406 localhost wikiuser Update INSERT /* MediaWiki\Extension\CampaignEvents\Questions\EventQuestionsStore::replaceEventQuestions */ INTO `ce_event_questions` (ceeq_event_id,ceeq_question_id) VALUES (3,1),(3,2),(3,3),(3,4),(3,5) 2024-12-05 14:49:58 213 [Note] InnoDB: *** (1) WAITING FOR THIS LOCK TO BE GRANTED: RECORD LOCKS space id 115 page no 4 n bits 72 index ceeq_event_question of table `wikidb`.`ce_event_questions` trx id 1780 lock_mode X insert intention waiting Record lock, heap no 1 PHYSICAL RECORD: n_fields 1; compact format; info bits 0 0: len 8; hex 73757072656d756d; asc supremum;; 2024-12-05 14:49:58 213 [Note] InnoDB: *** (2) TRANSACTION: TRANSACTION 1779, ACTIVE 0 sec inserting mysql tables in use 1, locked 1 9 lock struct(s), heap size 1128, 5 row lock(s), undo log entries 2 MySQL thread id 213, OS thread handle 139981052729088, query id 3404 localhost wikiuser Update INSERT /* MediaWiki\Extension\CampaignEvents\Questions\EventQuestionsStore::replaceEventQuestions */ INTO `ce_event_questions` (ceeq_event_id,ceeq_question_id) VALUES (2,1),(2,2),(2,3),(2,4),(2,5) 2024-12-05 14:49:58 213 [Note] InnoDB: *** (2) HOLDS THE LOCK(S): RECORD LOCKS space id 115 page no 4 n bits 72 index ceeq_event_question of table `wikidb`.`ce_event_questions` trx id 1779 lock_mode X Record lock, heap no 1 PHYSICAL RECORD: n_fields 1; compact format; info bits 0 0: len 8; hex 73757072656d756d; asc supremum;; 2024-12-05 14:49:58 213 [Note] InnoDB: *** (2) WAITING FOR THIS LOCK TO BE GRANTED: RECORD LOCKS space id 115 page no 4 n bits 72 index ceeq_event_question of table `wikidb`.`ce_event_questions` trx id 1779 lock_mode X insert intention waiting Record lock, heap no 1 PHYSICAL RECORD: n_fields 1; compact format; info bits 0 0: len 8; hex 73757072656d756d; asc supremum;; 2024-12-05 14:49:58 213 [Note] InnoDB: *** WE ROLL BACK TRANSACTION (1)
I have already investigated this and will write a report in a comment. But the key takeaway is that the relevant code is prone to lock contention, and this is probably also happening in production (and not just tests).