mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-20 01:15:35 +01:00
Shared/Database: Improve dead-lock error handling
Improve dead-lock error handling by making sure only 1 thread at time retries to execute a transaction so they don't keep dead-locking each other.
(cherry picked from commit 62001360dd)
This commit is contained in:
@@ -19,6 +19,8 @@
|
||||
#include "Transaction.h"
|
||||
#include <mysqld_error.h>
|
||||
|
||||
std::mutex TransactionTask::_deadlockLock;
|
||||
|
||||
//- Append a raw ad-hoc query to the transaction
|
||||
void Transaction::Append(const char* sql)
|
||||
{
|
||||
@@ -81,6 +83,8 @@ bool TransactionTask::Execute()
|
||||
|
||||
if (errorCode == ER_LOCK_DEADLOCK)
|
||||
{
|
||||
// Make sure only 1 async thread retries a transaction so they don't keep dead-locking each other
|
||||
std::lock_guard<std::mutex> lock(_deadlockLock);
|
||||
uint8 loopBreaker = 5; // Handle MySQL Errno 1213 without extending deadlock to the core itself
|
||||
for (uint8 i = 0; i < loopBreaker; ++i)
|
||||
if (!m_conn->ExecuteTransaction(m_trans))
|
||||
|
||||
Reference in New Issue
Block a user