From: Remi Gacogne Date: Thu, 28 Sep 2023 12:13:59 +0000 (+0200) Subject: dnsdist: Fix a race in the Async unit tests X-Git-Tag: dnsdist-1.8.3~2^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=839f9de07a4aff0cb6f803772f0b2a6bd482de0f;p=thirdparty%2Fpdns.git dnsdist: Fix a race in the Async unit tests 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` fixes it. (cherry picked from commit f39b15a71271afe6333e55f5994b680a68eeccbd) --- diff --git a/pdns/dnsdistdist/test-dnsdistasync.cc b/pdns/dnsdistdist/test-dnsdistasync.cc index b1fbebca05..7e8e13704e 100644 --- a/pdns/dnsdistdist/test-dnsdistasync.cc +++ b/pdns/dnsdistdist/test-dnsdistasync.cc @@ -49,7 +49,7 @@ public: errorRaised = true; } - bool errorRaised{false}; + std::atomic errorRaised{false}; }; struct DummyCrossProtocolQuery : public CrossProtocolQuery @@ -131,7 +131,7 @@ BOOST_AUTO_TEST_CASE(test_TimeoutFailClose) usleep(20000); BOOST_CHECK(holder->empty()); - BOOST_CHECK(sender->errorRaised); + BOOST_CHECK(sender->errorRaised.load()); holder->stop(); } @@ -159,7 +159,7 @@ BOOST_AUTO_TEST_CASE(test_AddingExpiredEvent) usleep(20000); BOOST_CHECK(holder->empty()); - BOOST_CHECK(sender->errorRaised); + BOOST_CHECK(sender->errorRaised.load()); holder->stop(); }