Skip to content

Commit

Permalink
dnsdist: Fix a race in the Async unit tests
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rgacogne committed Sep 28, 2023
1 parent 598ddcb commit f39b15a
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pdns/dnsdistdist/test-dnsdistasync.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class DummyQuerySender : public TCPQuerySender
errorRaised = true;
}

bool errorRaised{false};
std::atomic<bool> errorRaised{false};
};

struct DummyCrossProtocolQuery : public CrossProtocolQuery
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit f39b15a

Please sign in to comment.