]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Fix a race in the Async unit tests 13304/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 28 Sep 2023 12:13:59 +0000 (14:13 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 28 Sep 2023 12:13:59 +0000 (14:13 +0200)
We used to set the `errorRaised` variable from the `AsynchronousHolder`
thread then check its value from the main thread, which is correctly
reported as TSAN as a data race. We do know that we have waited enough,
and that otherwise it's fine to fail, but TSAN cannot know that. Switching
to a `std::atomic<bool>` fixes it.

pdns/dnsdistdist/test-dnsdistasync.cc

index 713c5ad71f248dc513a493c08d6132644074256c..044d5a02f30fb87153b13c64aa10e02fe875b108 100644 (file)
@@ -49,7 +49,7 @@ public:
     errorRaised = true;
   }
 
-  bool errorRaised{false};
+  std::atomic<bool> errorRaised{false};
 };
 
 struct DummyCrossProtocolQuery : public CrossProtocolQuery
@@ -137,7 +137,7 @@ BOOST_AUTO_TEST_CASE(test_TimeoutFailClose)
   }
 
   BOOST_CHECK(holder->empty());
-  BOOST_CHECK(sender->errorRaised);
+  BOOST_CHECK(sender->errorRaised.load());
 
   holder->stop();
 }
@@ -170,7 +170,7 @@ BOOST_AUTO_TEST_CASE(test_AddingExpiredEvent)
   }
 
   BOOST_CHECK(holder->empty());
-  BOOST_CHECK(sender->errorRaised);
+  BOOST_CHECK(sender->errorRaised.load());
 
   holder->stop();
 }