]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Increment the DoH ref counter before writing to the pipe
authorRemi Gacogne <remi.gacogne@powerdns.com>
Wed, 8 Dec 2021 14:31:18 +0000 (15:31 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Wed, 8 Dec 2021 14:31:18 +0000 (15:31 +0100)
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

index af1291d5a6d011829d45fb83c5fd58f337969a94..c8611879f7482ef0baaf62a443d39c0badfaad41 100644 (file)
@@ -228,6 +228,7 @@ struct DOHServerConfig
 static void sendDoHUnitToTheMainThread(std::unique_ptr<DOHUnit, void(*)(DOHUnit*)>&& 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_ptr<DOHUnit, void(*)(DOHUnit*
 
     ptr->release();
   }
+  ptr->release();
 }
 
 /* This function is called from other threads than the main DoH one,