Shared/Metric: Fix crash on shutdown

Fix crash on shutdown with metrics enabled but InfluxDB stopping before worldserver
This commit is contained in:
jackpoz
2017-12-17 14:35:18 +01:00
parent 3bb166dd5c
commit 45b2bcfaf2
3 changed files with 6 additions and 5 deletions

View File

@@ -213,16 +213,17 @@ void Metric::ScheduleSend()
}
}
void Metric::ForceSend()
void Metric::Unload()
{
// Send what's queued only if io_service is stopped (so only on shutdown)
if (_enabled && _batchTimer->get_io_service().stopped())
{
_enabled = false;
SendBatch();
_batchTimer->cancel();
_overallStatusTimer->cancel();
}
_batchTimer->cancel();
_overallStatusTimer->cancel();
}
void Metric::ScheduleOverallStatusLog()

View File

@@ -115,7 +115,7 @@ public:
void LogEvent(std::string const& category, std::string const& title, std::string const& description);
void ForceSend();
void Unload();
bool IsEnabled() const { return _enabled; }
};

View File

@@ -232,7 +232,7 @@ extern int main(int argc, char** argv)
std::shared_ptr<void> sMetricHandle(nullptr, [](void*)
{
TC_METRIC_EVENT("events", "Worldserver shutdown", "");
sMetric->ForceSend();
sMetric->Unload();
});
sScriptMgr->SetScriptLoader(AddScripts);