From: Remi Gacogne Date: Fri, 10 Oct 2025 08:18:40 +0000 (+0200) Subject: dnsdist: Make the round-robin LB policy internal counter atomic X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F16320%2Fhead;p=thirdparty%2Fpdns.git dnsdist: Make the round-robin LB policy internal counter atomic Otherwise TSAN is rightfully complaining that there is a data race because several threads are updating at the same time. While the impact of this counter being corrupted is almost zero, and there is an actual overhead to making it atomic, I believe this is the only correct way to ensure the expected behaviour of this policy. Signed-off-by: Remi Gacogne (cherry picked from commit 1ad48b108eadbe260c16443c1feaf393a2c1324b) --- diff --git a/pdns/dnsdistdist/dnsdist-lbpolicies.cc b/pdns/dnsdistdist/dnsdist-lbpolicies.cc index ac17eb5efa..21faf0c9e2 100644 --- a/pdns/dnsdistdist/dnsdist-lbpolicies.cc +++ b/pdns/dnsdistdist/dnsdist-lbpolicies.cc @@ -255,7 +255,7 @@ shared_ptr roundrobin(const ServerPolicy::NumberedServerVector& } } - static unsigned int counter; + static std::atomic counter{0}; return servers.at(candidates.at((counter++) % candidates.size()) - 1).second; }