From a52681a09f79ccadf6c471bf2fe056a32ff1dc0b Mon Sep 17 00:00:00 2001 From: Mikhail Montsev Date: Fri, 1 Nov 2024 14:04:16 +0000 Subject: [PATCH] teach TSAN to shut up and do not report data race in cloud/storage/core/libs/grpc/init.cpp (#2403) --- cloud/storage/core/libs/grpc/init.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/cloud/storage/core/libs/grpc/init.cpp b/cloud/storage/core/libs/grpc/init.cpp index 61e1e7cc04b..468d006716e 100644 --- a/cloud/storage/core/libs/grpc/init.cpp +++ b/cloud/storage/core/libs/grpc/init.cpp @@ -7,6 +7,7 @@ #include #include +#include #include #include @@ -72,6 +73,10 @@ void AddLog(gpr_log_func_args* args) auto& state = TGrpcState::Instance(); + // TSAN does not understand |std::atomic_thread_fence|, so teach it +#if defined(_tsan_enabled_) + __tsan_acquire(&state.Log); +#endif state.Log << LogSeverityToPriority(args->severity) << TSourceLocation(file.As(), args->line) << ": " << args->message; @@ -127,8 +132,12 @@ void GrpcLoggerInit(const TLog& log, bool enableTracing) auto& state = TGrpcState::Instance(); state.Log = log; // |gpr_set_log_verbosity| and |gpr_set_log_function| do not imply any - // memory barrier, so we need a full barrier here. + // memory barrier, so we need a full barrier here std::atomic_thread_fence(std::memory_order_seq_cst); + // TSAN does not understand |std::atomic_thread_fence|, so teach it +#if defined(_tsan_enabled_) + __tsan_release(&state.Log); +#endif gpr_set_log_verbosity(LogPriorityToSeverity(log.FiltrationLevel())); gpr_set_log_function(AddLog);