From 1ad48b108eadbe260c16443c1feaf393a2c1324b 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 --- 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 20e6d65afa..7abd925848 100644 --- a/pdns/dnsdistdist/dnsdist-lbpolicies.cc +++ b/pdns/dnsdistdist/dnsdist-lbpolicies.cc @@ -244,7 +244,7 @@ std::optional roundrobin(const ServerPolic return std::nullopt; } - static unsigned int counter; + static std::atomic counter{0}; size_t serverIdx = (counter++) % servers.size(); auto currentServer = servers.at(serverIdx); -- 2.47.3