[TSAN] Fix tsan bugs (part 1) (#5162)

ThreadSanitizer, aka TSAN, is a useful tool to detect multi-thread
problems, such as data race, mutex problems, etc.
We should detect TSAN problems for Doris BE, both unit tests and
server should pass through TSAN mode, to make Doris more robustness.
This is the very beginning patch to fix TSAN problems, and some
difficult problems are suppressed in file 'tsan_suppressions', you
can suppress these problems by setting:
export TSAN_OPTIONS="suppressions=tsan_suppressions"

before running:
`BUILD_TYPE=tsan ./run-be-ut.sh --run`
This commit is contained in:
Yingchun Lai
2021-01-15 09:45:11 +08:00
committed by GitHub
parent 07eaf50084
commit 58e58c94d8
25 changed files with 239 additions and 156 deletions

View File

@ -11,6 +11,7 @@
#include <ctime>
#include "common/logging.h"
#include "util/debug/sanitizer_scopes.h"
#include "util/monotime.h"
#include "util/mutex.h"
@ -33,11 +34,13 @@ ConditionVariable::~ConditionVariable() {
}
void ConditionVariable::wait() const {
debug::ScopedTSANIgnoreReadsAndWrites ignore_tsan;
int rv = pthread_cond_wait(&_condition, _user_mutex);
DCHECK_EQ(0, rv);
}
bool ConditionVariable::wait_until(const MonoTime& until) const {
debug::ScopedTSANIgnoreReadsAndWrites ignore_tsan;
// Have we already timed out?
MonoTime now = MonoTime::Now();
if (now > until) {
@ -53,6 +56,7 @@ bool ConditionVariable::wait_until(const MonoTime& until) const {
}
bool ConditionVariable::wait_for(const MonoDelta& delta) const {
debug::ScopedTSANIgnoreReadsAndWrites ignore_tsan;
// Negative delta means we've already timed out.
int64_t nsecs = delta.ToNanoseconds();
if (nsecs < 0) {