From c25e045e701e74e0489635a01d500a076f2b92f8 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Tue, 1 Aug 2017 10:39:16 +0200 Subject: [PATCH] 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. --- pdns/rec_channel_rec.cc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) 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); -- 2.47.2