mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-20 09:17:36 +01:00
Change the freeze detector thread to be a periodic callback running on the thread pool
This commit is contained in:
@@ -137,7 +137,7 @@ int main(int argc, char** argv)
|
||||
|
||||
// Enabled a timed callback for handling the database keep alive ping
|
||||
_dbPingInterval = sConfigMgr->GetIntDefault("MaxPingTime", 30);
|
||||
_dbPingTimer.expires_from_now(boost::posix_time::seconds(_dbPingInterval));
|
||||
_dbPingTimer.expires_from_now(boost::posix_time::minutes(_dbPingInterval));
|
||||
_dbPingTimer.async_wait(KeepDatabaseAliveHandler);
|
||||
|
||||
// Start the io service worker loop
|
||||
@@ -218,6 +218,7 @@ void KeepDatabaseAliveHandler(const boost::system::error_code& error)
|
||||
LoginDatabase.KeepAlive();
|
||||
|
||||
_dbPingTimer.expires_from_now(boost::posix_time::minutes(_dbPingInterval));
|
||||
_dbPingTimer.async_wait(KeepDatabaseAliveHandler);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include <openssl/opensslv.h>
|
||||
#include <openssl/crypto.h>
|
||||
#include <boost/asio/io_service.hpp>
|
||||
#include <boost/asio/deadline_timer.hpp>
|
||||
|
||||
#include "Common.h"
|
||||
#include "DatabaseEnv.h"
|
||||
@@ -62,6 +63,11 @@ int m_ServiceStatus = -1;
|
||||
#endif
|
||||
|
||||
boost::asio::io_service _ioService;
|
||||
boost::asio::deadline_timer _freezeCheckTimer(_ioService);
|
||||
uint32 _worldLoopCounter(0);
|
||||
uint32 _lastChangeMsTime(0);
|
||||
uint32 _maxCoreStuckTime(0);
|
||||
|
||||
WorldDatabaseWorkerPool WorldDatabase; ///< Accessor to the world database
|
||||
CharacterDatabaseWorkerPool CharacterDatabase; ///< Accessor to the character database
|
||||
LoginDatabaseWorkerPool LoginDatabase; ///< Accessor to the realm/login database
|
||||
@@ -69,7 +75,7 @@ uint32 realmID; ///< Id of the realm
|
||||
|
||||
void usage(const char* prog);
|
||||
void SignalHandler(const boost::system::error_code& error, int signalNumber);
|
||||
void FreezeDetectorThread(uint32 delayTime);
|
||||
void FreezeDetectorHandler(const boost::system::error_code& error);
|
||||
AsyncAcceptor<RASession>* StartRaSocketAcceptor(boost::asio::io_service& ioService);
|
||||
bool StartDB();
|
||||
void StopDB();
|
||||
@@ -219,11 +225,6 @@ extern int main(int argc, char** argv)
|
||||
soapThread = new std::thread(TCSoapThread, sConfigMgr->GetStringDefault("SOAP.IP", "127.0.0.1"), uint16(sConfigMgr->GetIntDefault("SOAP.Port", 7878)));
|
||||
}
|
||||
|
||||
// Start up freeze catcher thread
|
||||
std::thread* freezeDetectorThread = nullptr;
|
||||
if (uint32 freezeDelay = sConfigMgr->GetIntDefault("MaxCoreStuckTime", 0))
|
||||
freezeDetectorThread = new std::thread(FreezeDetectorThread, freezeDelay);
|
||||
|
||||
// Launch the worldserver listener socket
|
||||
uint16 worldPort = uint16(sWorld->getIntConfig(CONFIG_PORT_WORLD));
|
||||
std::string worldListener = sConfigMgr->GetStringDefault("BindIP", "0.0.0.0");
|
||||
@@ -235,6 +236,15 @@ extern int main(int argc, char** argv)
|
||||
// Set server online (allow connecting now)
|
||||
LoginDatabase.DirectPExecute("UPDATE realmlist SET flag = flag & ~%u, population = 0 WHERE id = '%u'", REALM_FLAG_INVALID, realmID);
|
||||
|
||||
// Start the freeze check callback cycle in 5 seconds (cycle itself is 1 sec)
|
||||
std::thread* freezeDetectorThread = nullptr;
|
||||
if (_maxCoreStuckTime = sConfigMgr->GetIntDefault("MaxCoreStuckTime", 0))
|
||||
{
|
||||
_freezeCheckTimer.expires_from_now(boost::posix_time::seconds(5));
|
||||
_freezeCheckTimer.async_wait(FreezeDetectorHandler);
|
||||
TC_LOG_INFO("server.worldserver", "Starting up anti-freeze thread (%u seconds max stuck time)...", _maxCoreStuckTime);
|
||||
}
|
||||
|
||||
TC_LOG_INFO("server.worldserver", "%s (worldserver-daemon) ready...", _FULLVERSION);
|
||||
|
||||
WorldUpdateLoop();
|
||||
@@ -408,34 +418,28 @@ void SignalHandler(const boost::system::error_code& error, int signalNumber)
|
||||
}
|
||||
}
|
||||
|
||||
void FreezeDetectorThread(uint32 delayTime)
|
||||
void FreezeDetectorHandler(const boost::system::error_code& error)
|
||||
{
|
||||
if (!delayTime)
|
||||
return;
|
||||
|
||||
TC_LOG_INFO("server.worldserver", "Starting up anti-freeze thread (%u seconds max stuck time)...", delayTime / 1000);
|
||||
uint32 loops = 0;
|
||||
uint32 lastChange = 0;
|
||||
|
||||
while (!World::IsStopped())
|
||||
if (!error)
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
uint32 curtime = getMSTime();
|
||||
// normal work
|
||||
|
||||
uint32 worldLoopCounter = World::m_worldLoopCounter;
|
||||
if (loops != worldLoopCounter)
|
||||
if (_worldLoopCounter != worldLoopCounter)
|
||||
{
|
||||
lastChange = curtime;
|
||||
loops = worldLoopCounter;
|
||||
_lastChangeMsTime = curtime;
|
||||
_worldLoopCounter = worldLoopCounter;
|
||||
}
|
||||
// possible freeze
|
||||
else if (getMSTimeDiff(lastChange, curtime) > delayTime)
|
||||
else if (getMSTimeDiff(_lastChangeMsTime, curtime) > _maxCoreStuckTime)
|
||||
{
|
||||
TC_LOG_ERROR("server.worldserver", "World Thread hangs, kicking out server!");
|
||||
ASSERT(false);
|
||||
}
|
||||
|
||||
_freezeCheckTimer.expires_from_now(boost::posix_time::seconds(1));
|
||||
_freezeCheckTimer.async_wait(FreezeDetectorHandler);
|
||||
}
|
||||
TC_LOG_INFO("server.worldserver", "Anti-freeze thread exiting without problems.");
|
||||
}
|
||||
|
||||
AsyncAcceptor<RASession>* StartRaSocketAcceptor(boost::asio::io_service& ioService)
|
||||
|
||||
Reference in New Issue
Block a user