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: rec-5.0.0-alpha2~33^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F13304%2Fhead;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. --- diff --git a/pdns/dnsdistdist/test-dnsdistasync.cc b/pdns/dnsdistdist/test-dnsdistasync.cc index 713c5ad71f..044d5a02f3 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 @@ -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(); }