From c7c72e0f57e63d1fd7b77edf19c171a21f555760 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Fri, 10 Oct 2025 10:18:40 +0200 Subject: [PATCH] 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) --- pdns/dnsdistdist/dnsdist-lbpolicies.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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; } -- 2.47.3