]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Make the round-robin LB policy internal counter atomic 16241/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 10 Oct 2025 08:18:40 +0000 (10:18 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 10 Oct 2025 08:18:40 +0000 (10:18 +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>
pdns/dnsdistdist/dnsdist-lbpolicies.cc

index 20e6d65afa98c7edfd05176d8c73ba40a9bb8801..7abd92584813f535627347b6fc6b5c3482021e5b 100644 (file)
@@ -244,7 +244,7 @@ std::optional<ServerPolicy::SelectedServerPosition> roundrobin(const ServerPolic
     return std::nullopt;
   }
 
-  static unsigned int counter;
+  static std::atomic<unsigned int> counter{0};
 
   size_t serverIdx = (counter++) % servers.size();
   auto currentServer = servers.at(serverIdx);