Fixed Deadlock in markThreadReadByUser

Affected version
2.1.3

Xon

Well-known member
Code:
XF\Db\DeadlockException: MySQL query error [1213]: Deadlock found when trying to get lock; try restarting transaction
src/XF/Db/AbstractStatement.php:217

[SIZE=5][B]Stack trace[/B][/SIZE]
INSERT  INTO `xf_thread_read` (`thread_id`, `user_id`, `thread_read_date`) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE thread_read_date = VALUES(thread_read_date)
------------

#0 src/XF/Db/Mysqli/Statement.php(196): XF\Db\AbstractStatement->getException('MySQL query err...', 1213, '40001')
#1 src/XF/Db/Mysqli/Statement.php(77): XF\Db\Mysqli\Statement->getException('MySQL query err...', 1213, '40001')
#2 src/XF/Db/AbstractAdapter.php(94): XF\Db\Mysqli\Statement->execute()
#3 src/XF/Db/AbstractAdapter.php(221): XF\Db\AbstractAdapter->query('INSERT INTO `x...', Array)
#4 src/XF/Repository/Thread.php(236): XF\Db\AbstractAdapter->insert('xf_thread_read', Array, false, 'thread_read_dat...')
#5 src/XF/Repository/Thread.php(257): XF\Repository\Thread->markThreadReadByUser(Object(SV\CollaborativeThreads\XF\Entity\Thread), Object(SV\ConversationSharing\XF\Entity\User), 1565728468)
#6 src/XF/Pub/Controller/Thread.php(89): XF\Repository\Thread->markThreadReadByVisitor(Object(SV\CollaborativeThreads\XF\Entity\Thread), 1565728468)
#7 src/addons/SV/UserActivity/XF/Pub/Controller/Thread.php(15): XF\Pub\Controller\Thread->actionIndex(Object(XF\Mvc\ParameterBag))
#8 src/addons/SV/UserEssentials/XF/Pub/Controller/Thread.php(20): SV\UserActivity\XF\Pub\Controller\Thread->actionIndex(Object(XF\Mvc\ParameterBag))
#9 src/addons/SV/AlertImprovements/XF/Pub/Controller/Thread.php(24): SV\UserEssentials\XF\Pub\Controller\Thread->actionIndex(Object(XF\Mvc\ParameterBag))
#10 src/addons/SV/Threadmarks/XF/Pub/Controller/Thread.php(107): SV\AlertImprovements\XF\Pub\Controller\Thread->actionIndex(Object(XF\Mvc\ParameterBag))
#11 src/addons/SV/ElasticSearchEssentials/XF/Pub/Controller/Thread.php(23): SV\Threadmarks\XF\Pub\Controller\Thread->actionIndex(Object(XF\Mvc\ParameterBag))
#12 src/XF/Mvc/Dispatcher.php(321): SV\ElasticSearchEssentials\XF\Pub\Controller\Thread->actionIndex(Object(XF\Mvc\ParameterBag))
#13 src/XF/Mvc/Dispatcher.php(248): XF\Mvc\Dispatcher->dispatchClass('XF:Thread', 'Index', Object(XF\Mvc\RouteMatch), Object(SV\ElasticSearchEssentials\XF\Pub\Controller\Thread), NULL)
#14 src/XF/Mvc/Dispatcher.php(100): XF\Mvc\Dispatcher->dispatchFromMatch(Object(XF\Mvc\RouteMatch), Object(SV\ElasticSearchEssentials\XF\Pub\Controller\Thread), NULL)
#15 src/XF/Mvc/Dispatcher.php(50): XF\Mvc\Dispatcher->dispatchLoop(Object(XF\Mvc\RouteMatch))
#16 src/XF/App.php(2177): XF\Mvc\Dispatcher->run()
#17 src/XF.php(390): XF\App->run()
#18 index.php(20): XF::runApp('XF\\Pub\\App')
#19 {main}
I've seen this pop-up a few times, using executeTransaction with a retry or a catch on DeadlockException would make sense.

Note; none of my add-ons are extending this function or wrapping it in a transaction
 

XF Bug Bot

XenForo bug fixer bot
Staff member
Thank you for reporting this issue. It has now been resolved and we are aiming to include it in a future XF release (2.1.4).

Change log:
Wrap markForumReadByUser query in a separate transaction and attempt retry on deadlock
Any changes made as a result of this issue being resolved may not be rolled out here until later.
 
Top