]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Make the round-robin LB policy internal counter atomic 16320/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 10 Oct 2025 08:18:40 +0000 (10:18 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 20 Oct 2025 09:06:33 +0000 (11:06 +0200)
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 <remi.gacogne@powerdns.com>
(cherry picked from commit 1ad48b108eadbe260c16443c1feaf393a2c1324b)

pdns/dnsdistdist/dnsdist-lbpolicies.cc

index ac17eb5efab1ba558230e3a1c350c4e2b7ce5e74..21faf0c9e26d903669157790036ca4cc00ff2422 100644 (file)
@@ -255,7 +255,7 @@ shared_ptr<DownstreamState> roundrobin(const ServerPolicy::NumberedServerVector&
     }
   }
 
-  static unsigned int counter;
+  static std::atomic<unsigned int> counter{0};
   return servers.at(candidates.at((counter++) % candidates.size()) - 1).second;
 }