From: Remi Gacogne Date: Tue, 1 Aug 2017 08:39:16 +0000 (+0200) Subject: rec: Guard `registerAllStats()` with an atomic flag instead of a bool X-Git-Tag: auth-4.1.0-rc1~8^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F5567%2Fhead;p=thirdparty%2Fpdns.git rec: Guard `registerAllStats()` with an atomic flag instead of a bool Unlikely as it seems, I just got hit by a race where three threads were trying to register the stats at the same time, causing my starting recursor to stay stuck while consuming a lot of CPU. --- diff --git a/pdns/rec_channel_rec.cc b/pdns/rec_channel_rec.cc index 2d086f1ed4..e79dd250e7 100644 --- a/pdns/rec_channel_rec.cc +++ b/pdns/rec_channel_rec.cc @@ -775,10 +775,9 @@ extern ResponseStats g_rs; void registerAllStats() { - static bool s_init = false; - if(s_init) + static std::atomic_flag s_init = ATOMIC_FLAG_INIT; + if(s_init.test_and_set()) return; - s_init=true; addGetStat("questions", &g_stats.qcounter); addGetStat("ipv6-questions", &g_stats.ipv6qcounter);