From 05a292633cdfdb9383d0a914d5b95c838837e1eb Mon Sep 17 00:00:00 2001 From: Machiavelli Date: Sun, 31 Oct 2010 10:55:29 +0100 Subject: [PATCH] =?UTF-8?q?Core/DBLayer:=20-=20Fix=20a=20race=20condition?= =?UTF-8?q?=20in=20KeepAlive()=20when=20connections=20are=20using=20mysql?= =?UTF-8?q?=20context=20when=20ping=20is=20called.=20-=20Don=C2=B4t=20wait?= =?UTF-8?q?=20for=20locks=20to=20be=20released=20on=20a=20connection=20whe?= =?UTF-8?q?n=20pinging,=20this=20means=20the=20connection=20is=20not=20idl?= =?UTF-8?q?e=20and=20locking=20is=20redundant.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Patch by admin@****.net Fixes issue #4599 --HG-- branch : trunk --- .../shared/Database/DatabaseWorkerPool.h | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/server/shared/Database/DatabaseWorkerPool.h b/src/server/shared/Database/DatabaseWorkerPool.h index 899c0f8f63d..9f7bf6d72dc 100755 --- a/src/server/shared/Database/DatabaseWorkerPool.h +++ b/src/server/shared/Database/DatabaseWorkerPool.h @@ -37,13 +37,12 @@ class PingOperation : public SQLOperation /// Operation for idle delaythreads bool Execute() { - for (;;) - if (m_conn->LockIfReady()) - { - m_conn->Ping(); - m_conn->Unlock(); - return true; - } + if (m_conn->LockIfReady()) + { + m_conn->Ping(); + m_conn->Unlock(); + return true; + } return false; } @@ -305,10 +304,17 @@ class DatabaseWorkerPool void KeepAlive() { - /// Ping syncrhonous connections + /// Ping synchronous connections for (uint8 i = 0; i < m_connections[IDX_SYNCH].size(); ++i) - m_connections[IDX_SYNCH][i]->Ping(); - + { + T* t = m_connections[IDX_SYNCH][i]; + if (t->LockIfReady()) + { + t->Ping(); + t->Unlock(); + } + } + /// Assuming all worker threads are free, every worker thread will receive 1 ping operation request /// If one or more worker threads are busy, the ping operations will not be split evenly, but this doesn't matter /// as the sole purpose is to prevent connections from idling.