From: Remi Gacogne Date: Wed, 8 Dec 2021 14:31:18 +0000 (+0100) Subject: dnsdist: Increment the DoH ref counter before writing to the pipe X-Git-Tag: auth-4.7.0-alpha1~122^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7a90dbde7b01321783d73d71520abd3fa380a9c8;p=thirdparty%2Fpdns.git 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. --- 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,