From f39b15a71271afe6333e55f5994b680a68eeccbd Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Thu, 28 Sep 2023 14:13:59 +0200 Subject: [PATCH] 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. --- pdns/dnsdistdist/test-dnsdistasync.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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(); } -- 2.47.2