From 7a90dbde7b01321783d73d71520abd3fa380a9c8 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Wed, 8 Dec 2021 15:31:18 +0100 Subject: [PATCH] dnsdist: Increment the DoH ref counter before writing to the pipe As far as I can tell this is not actually needed, as we decrement it right away, but it prevents TSAN from reporting a race when the UDP response comes very fast, is truncated, and the query is then passed to a TCP worker. TSAN seems to think that the thread is still sending the UDP query when we touch it again in the TCP worker, which does not really make sense to me. My guess is that the memory barrier needed to update the ref counter makes TSAN happy, but I might be missing something. --- pdns/dnsdistdist/doh.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pdns/dnsdistdist/doh.cc b/pdns/dnsdistdist/doh.cc index af1291d5a6..c8611879f7 100644 --- a/pdns/dnsdistdist/doh.cc +++ b/pdns/dnsdistdist/doh.cc @@ -228,6 +228,7 @@ struct DOHServerConfig static void sendDoHUnitToTheMainThread(std::unique_ptr&& du, const char* description) { auto ptr = du.release(); + ptr->get(); static_assert(sizeof(ptr) <= PIPE_BUF, "Writes up to PIPE_BUF are guaranteed not to be interleaved and to either fully succeed or fail"); ssize_t sent = write(ptr->rsock, &ptr, sizeof(ptr)); @@ -242,6 +243,7 @@ static void sendDoHUnitToTheMainThread(std::unique_ptrrelease(); } + ptr->release(); } /* This function is called from other threads than the main DoH one, -- 2.47.2