From ad949cc46b4162d45497c406ca5f971d96affb2e Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Wed, 10 May 2023 14:47:44 +0200 Subject: [PATCH] dnsdist: Suppress a race warning when setting a backend health-check mode There is an actual race when one thread, likely the console, changes the health-check mode of a given backend just when the health-check thread is determining whether it should send a health-check probe. We are fine with getting a wrong value in the health-check thread, as long as we eventually get the new one, so let's not worry about it and add a TSAN suppression. The TSAN report was: ``` WARNING: ThreadSanitizer: data race (pid=5301) Read of size 1 at 0x7b78000002ae by thread T11: #0 DownstreamState::healthCheckRequired(std::optional) /__w/pdns/pdns/pdns/dnsdistdist/dnsdist-backend.cc:555:16 (dnsdist+0x18f003) #1 healthChecksThread() /__w/pdns/pdns/pdns/dnsdistdist/dnsdist.cc:2046:17 (dnsdist+0x811ea9) #2 void std::__invoke_impl(std::__invoke_other, void (*&&)()) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/invoke.h:60:14 (dnsdist+0x1dfe39) #3 std::__invoke_result::type std::__invoke(void (*&&)()) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/invoke.h:95:14 (dnsdist+0x1dfe39) #4 void std::thread::_Invoker >::_M_invoke<0ul>(std::_Index_tuple<0ul>) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/thread:264:13 (dnsdist+0x1dfe39) #5 std::thread::_Invoker >::operator()() /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/thread:271:11 (dnsdist+0x1dfe39) #6 std::thread::_State_impl > >::_M_run() /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/thread:215:13 (dnsdist+0x1dfe39) #7 (libstdc++.so.6+0xceecf) Previous write of size 1 at 0x7b78000002ae by thread T21 (mutexes: write M189): #0 std::enable_if::value, setupLuaBindings(LuaContext&, bool)::$_15>::type LuaContext::readIntoFunction >(std::__cxx11::basic_string, std::allocator > const&, setupLuaBindings(LuaContext&, bool)::$_15, LuaContext::tag, LuaContext::tag)>)::'lambda'(std::shared_ptr const&, boost::optional)&, std::shared_ptr const&>&, boost::optional >(lua_State*, LuaContext::tag, void&&, int, LuaContext::tag, LuaContext::tag >) /__w/pdns/pdns/pdns/dnsdistdist/./ext/luawrapper/include/LuaContext.hpp (dnsdist+0x4b6ab2) #1 std::enable_if::value), setupLuaBindings(LuaContext&, bool)::$_15>::type LuaContext::readIntoFunction >(std::__cxx11::basic_string, std::allocator > const&, setupLuaBindings(LuaContext&, bool)::$_15, LuaContext::tag, LuaContext::tag)>)::'lambda'(std::shared_ptr const&, boost::optional)&, std::shared_ptr, boost::optional >(lua_State*, LuaContext::tag, void&&, int, LuaContext::tag, LuaContext::tag >) /__w/pdns/pdns/pdns/dnsdistdist/./ext/luawrapper/include/LuaContext.hpp:1803:16 (dnsdist+0x4b6ab2) #2 std::enable_if<(std::integral_constant::value) && (!(std::is_void::value)), LuaContext::PushedObject>::type LuaContext::Pusher, boost::optional), void>::callback2 >(std::__cxx11::basic_string, std::allocator > const&, setupLuaBindings(LuaContext&, bool)::$_15, LuaContext::tag, LuaContext::tag)>)::'lambda'(std::shared_ptr const&, boost::optional)&>(lua_State*, setupLuaBindings(LuaContext&, bool)::$_15&&, int) /__w/pdns/pdns/pdns/dnsdistdist/./ext/luawrapper/include/LuaContext.hpp:2443:9 (dnsdist+0x4b6ab2) #3 LuaContext::PushedObject LuaContext::Pusher, boost::optional), void>::callback >(std::__cxx11::basic_string, std::allocator > const&, setupLuaBindings(LuaContext&, bool)::$_15, LuaContext::tag, LuaContext::tag)>)::'lambda'(std::shared_ptr const&, boost::optional)>(lua_State*, setupLuaBindings(LuaContext&, bool)::$_15*, int) /__w/pdns/pdns/pdns/dnsdistdist/./ext/luawrapper/include/LuaContext.hpp:2405:20 (dnsdist+0x4b6ab2) #4 std::enable_if::value, LuaContext::PushedObject>::type LuaContext::Pusher, boost::optional), void>::push >(std::__cxx11::basic_string, std::allocator > const&, setupLuaBindings(LuaContext&, bool)::$_15, LuaContext::tag, LuaContext::tag)>)::'lambda'(std::shared_ptr const&, boost::optional)>(lua_State*, setupLuaBindings(LuaContext&, bool)::$_15)::'lambda'(lua_State*)::operator()(lua_State*) const /__w/pdns/pdns/pdns/dnsdistdist/./ext/luawrapper/include/LuaContext.hpp:2334:20 (dnsdist+0x4b6ab2) #5 std::enable_if::value, LuaContext::PushedObject>::type LuaContext::Pusher, boost::optional), void>::push >(std::__cxx11::basic_string, std::allocator > const&, setupLuaBindings(LuaContext&, bool)::$_15, LuaContext::tag, LuaContext::tag)>)::'lambda'(std::shared_ptr const&, boost::optional)>(lua_State*, setupLuaBindings(LuaContext&, bool)::$_15)::'lambda'(lua_State*)::__invoke(lua_State*) /__w/pdns/pdns/pdns/dnsdistdist/./ext/luawrapper/include/LuaContext.hpp:2330:31 (dnsdist+0x4b6ab2) #6 (libluajit-5.1.so.2+0xa5e6) #7 boost::optional, std::allocator >, std::shared_ptr, ClientState*, std::unordered_map, std::allocator >, double, std::hash, std::allocator > >, std::equal_to, std::allocator > >, std::allocator, std::allocator > const, double> > > > > LuaContext::call, std::allocator >, std::shared_ptr, ClientState*, std::unordered_map, std::allocator >, double, std::hash, std::allocator > >, std::equal_to, std::allocator > >, std::allocator, std::allocator > const, double> > > > > >(lua_State*, LuaContext::PushedObject) /__w/pdns/pdns/pdns/dnsdistdist/./ext/luawrapper/include/LuaContext.hpp:1413:29 (dnsdist+0x1c2b4b) #8 boost::optional, std::allocator >, std::shared_ptr, ClientState*, std::unordered_map, std::allocator >, double, std::hash, std::allocator > >, std::equal_to, std::allocator > >, std::allocator, std::allocator > const, double> > > > > LuaContext::executeCode, std::allocator >, std::shared_ptr, ClientState*, std::unordered_map, std::allocator >, double, std::hash, std::allocator > >, std::equal_to, std::allocator > >, std::allocator, std::allocator > const, double> > > > > >(char const*) /__w/pdns/pdns/pdns/dnsdistdist/./ext/luawrapper/include/LuaContext.hpp:324:16 (dnsdist+0x1c2b4b) #9 boost::optional, std::allocator >, std::shared_ptr, ClientState*, std::unordered_map, std::allocator >, double, std::hash, std::allocator > >, std::equal_to, std::allocator > >, std::allocator, std::allocator > const, double> > > > > LuaContext::executeCode, std::allocator >, std::shared_ptr, ClientState*, std::unordered_map, std::allocator >, double, std::hash, std::allocator > >, std::equal_to, std::allocator > >, std::allocator, std::allocator > const, double> > > > > >(std::__cxx11::basic_string, std::allocator > const&) /__w/pdns/pdns/pdns/dnsdistdist/./ext/luawrapper/include/LuaContext.hpp:301:16 (dnsdist+0x1bf450) #10 controlClientThread(ConsoleConnection&&) /__w/pdns/pdns/pdns/dnsdistdist/dnsdist-console.cc:897:27 (dnsdist+0x1bf450) #11 boost::optional, std::allocator >, std::shared_ptr, ClientState*, std::unordered_map, std::allocator >, double, std::hash, std::allocator > >, std::equal_to, std::allocator > >, std::allocator, std::allocator > const, double> > > > > LuaContext::executeCode, std::allocator >, std::shared_ptr, ClientState*, std::unordered_map, std::allocator >, double, std::hash, std::allocator > >, std::equal_to, std::allocator > >, std::allocator, std::allocator > const, double> > > > > >(std::__cxx11::basic_string, std::allocator > const&) /__w/pdns/pdns/pdns/dnsdistdist/./ext/luawrapper/include/LuaContext.hpp:301:16 (dnsdist+0x1bf450) #12 controlClientThread(ConsoleConnection&&) /__w/pdns/pdns/pdns/dnsdistdist/dnsdist-console.cc:897:27 (dnsdist+0x1bf450) #13 void std::__invoke_impl(std::__invoke_other, void (*&&)(ConsoleConnection&&), ConsoleConnection&&) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/invoke.h:60:14 (dnsdist+0x1c76f3) #14 std::__invoke_result::type std::__invoke(void (*&&)(ConsoleConnection&&), ConsoleConnection&&) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/invoke.h:95:14 (dnsdist+0x1c76f3) #15 void std::thread::_Invoker >::_M_invoke<0ul, 1ul>(std::_Index_tuple<0ul, 1ul>) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/thread:264:13 (dnsdist+0x1c76f3) #16 std::thread::_Invoker >::operator()() /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/thread:271:11 (dnsdist+0x1c76f3) #17 std::thread::_State_impl > >::_M_run() /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/thread:215:13 (dnsdist+0x1c76f3) #18 (libstdc++.so.6+0xceecf) As if synchronized via sleep: #0 healthChecksThread() /__w/pdns/pdns/pdns/dnsdistdist/dnsdist.cc:2034:5 (dnsdist+0xc77e8) #1 void std::__invoke_impl(std::__invoke_other, void (*&&)()) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/invoke.h:60:14 (dnsdist+0x811b8e) #2 std::__invoke_result::type std::__invoke(void (*&&)()) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/invoke.h:95:14 (dnsdist+0x811b8e) #3 void std::thread::_Invoker >::_M_invoke<0ul>(std::_Index_tuple<0ul>) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/thread:264:13 (dnsdist+0x811b8e) #4 std::thread::_Invoker >::operator()() /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/thread:271:11 (dnsdist+0x811b8e) #5 std::thread::_State_impl > >::_M_run() /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/thread:215:13 (dnsdist+0x811b8e) #6 (dnsdist+0x1dfe39) #7 operator new(unsigned long, std::align_val_t) (libstdc++.so.6+0xceecf) Location is heap block of size 2880 at 0x7b7800000000 allocated by main thread: #0 __gnu_cxx::new_allocator, (__gnu_cxx::_Lock_policy)2> >::allocate(unsigned long, void const*) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/ext/new_allocator.h:112:31 (dnsdist+0x13f29c) #1 std::allocator_traits, (__gnu_cxx::_Lock_policy)2> > >::allocate(std::allocator, (__gnu_cxx::_Lock_policy)2> >&, unsigned long) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/alloc_traits.h:460:20 (dnsdist+0x13f29c) #2 std::__allocated_ptr, (__gnu_cxx::_Lock_policy)2> > > std::__allocate_guarded, (__gnu_cxx::_Lock_policy)2> > >(std::allocator, (__gnu_cxx::_Lock_policy)2> >&) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/allocated_ptr.h:97:21 (dnsdist+0x13f29c) #3 std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count, DownstreamState::Config, std::shared_ptr, bool>(DownstreamState*&, std::_Sp_alloc_shared_tag >, DownstreamState::Config&&, std::shared_ptr&&, bool&&) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/shared_ptr_base.h:680:19 (dnsdist+0x13f29c) #4 std::__shared_ptr::__shared_ptr, DownstreamState::Config, std::shared_ptr, bool>(std::_Sp_alloc_shared_tag >, DownstreamState::Config&&, std::shared_ptr&&, bool&&) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/shared_ptr_base.h:1371:14 (dnsdist+0x13f29c) #5 std::shared_ptr::shared_ptr, DownstreamState::Config, std::shared_ptr, bool>(std::_Sp_alloc_shared_tag >, DownstreamState::Config&&, std::shared_ptr&&, bool&&) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/shared_ptr.h:408:4 (dnsdist+0x1db3be) #6 std::shared_ptr std::allocate_shared, DownstreamState::Config, std::shared_ptr, bool>(std::allocator const&, DownstreamState::Config&&, std::shared_ptr&&, bool&&) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/shared_ptr.h:859:14 (dnsdist+0x1db3be) #7 std::shared_ptr std::make_shared, bool>(DownstreamState::Config&&, std::shared_ptr&&, bool&&) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/shared_ptr.h:875:14 (dnsdist+0x1db3be) #8 setupLuaConfig(LuaContext&, bool, bool)::$_3::operator()(boost::variant, std::allocator >, std::unordered_map, std::allocator >, boost::variant, std::allocator >, std::vector, std::allocator > >, std::allocator, std::allocator > > > >, std::function (DNSName const&, unsigned short, unsigned short, dnsheader*)> >, std::hash, std::allocator > >, std::equal_to, std::allocator > >, std::allocator, std::allocator > const, boost::variant, std::allocator >, std::vector, std::allocator > >, std::allocator, std::allocator > > > >, std::function (DNSName const&, unsigned short, unsigned short, dnsheader*)> > > > > >, boost::optional) const /__w/pdns/pdns/pdns/dnsdistdist/dnsdist-lua.cc:619:37 (dnsdist+0x1db3be) #9 tor > > > >, std::function (DNSName const&, unsigned short, unsigned short, dnsheader*)> > > > > >, boost::optional), void>::callback2(lua_State*, setupLuaConfig(LuaContext&, bool, bool)::$_3&, int) /__w/pdns/pdns/pdns/dnsdistdist/./ext/luawrapper/include/LuaContext.hpp:2436:31 (dnsdist+0x69065d) #10 LuaContext::PushedObject LuaContext::Pusher (boost::variant, std::allocator >, std::unordered_map, std::allocator >, boost::variant, std::allocator >, std::vector, std::allocator > >, std::allocator, std::allocator > > > >, std::function (DNSName const&, unsigned short, unsigned short, dnsheader*)> >, std::hash, std::allocator > >, std::equal_to, std::allocator > >, std::allocator, std::allocator > const, boost::variant, std::allocator >, std::vector, std::allocator > >, std::allocator, std::allocator > > > >, std::function (DNSName const&, unsigned short, unsigned short, dnsheader*)> > > > > >, boost::optional), void>::callback(lua_State*, setupLuaConfig(LuaContext&, bool, bool)::$_3*, int) /__w/pdns/pdns/pdns/dnsdistdist/./ext/luawrapper/include/LuaContext.hpp:2405:20 (dnsdist+0x69065d) #11 std::enable_if::value, LuaContext::PushedObject>::type LuaContext::Pusher (boost::variant, std::allocator >, std::unordered_map, std::allocator >, boost::variant, std::allocator >, std::vector, std::allocator > >, std::allocator, std::allocator > > > >, std::function (DNSName const&, unsigned short, unsigned short, dnsheader*)> >, std::hash, std::allocator > >, std::equal_to, std::allocator > >, std::allocator, std::allocator > const, boost::variant, std::allocator >, std::vector, std::allocator > >, std::allocator, std::allocator > > > >, std::function (DNSName const&, unsigned short, unsigned short, dnsheader*)> > > > > >, boost::optional), void>::push(lua_State*, setupLuaConfig(LuaContext&, bool, bool)::$_3)::'lambda'(lua_State*)::operator()(lua_State*) const /__w/pdns/pdns/pdns/dnsdistdist/./ext/luawrapper/include/LuaContext.hpp:2334:20 (dnsdist+0x69065d) #12 std::enable_if::value, LuaContext::PushedObject>::type LuaContext::Pusher (boost::variant, std::allocator >, std::unordered_map, std::allocator >, boost::variant, std::allocator >, std::vector, std::allocator > >, std::allocator, std::allocator > > > >, std::function (DNSName const&, unsigned short, unsigned short, dnsheader*)> >, std::hash, std::allocator > >, std::equal_to, std::allocator > >, std::allocator, std::allocator > const, boost::variant, std::allocator >, std::vector, std::allocator > >, std::allocator, std::allocator > > > >, std::function (DNSName const&, unsigned short, unsigned short, dnsheader*)> > > > > >, boost::optional), void>::push(lua_State*, setupLuaConfig(LuaContext&, bool, bool)::$_3)::'lambda'(lua_State*)::__invoke(lua_State*) /__w/pdns/pdns/pdns/dnsdistdist/./ext/luawrapper/include/LuaContext.hpp:2330:31 (dnsdist+0x69065d) #13 (dnsdist+0x687942) #14 (libluajit-5.1.so.2+0xa5e6) #15 std::tuple<> LuaContext::call >(lua_State*, LuaContext::PushedObject) /__w/pdns/pdns/pdns/dnsdistdist/./ext/luawrapper/include/LuaContext.hpp:1413:29 (dnsdist+0x577e85) #16 LuaContext::executeCode(std::istream&) /__w/pdns/pdns/pdns/dnsdistdist/./ext/luawrapper/include/LuaContext.hpp:267:9 (dnsdist+0x685db6) #17 setupLua(LuaContext&, bool, bool, std::__cxx11::basic_string, std::allocator > const&) /__w/pdns/pdns/pdns/dnsdistdist/dnsdist-lua.cc:3025:10 (dnsdist+0x67b759) #18 main /__w/pdns/pdns/pdns/dnsdistdist/dnsdist.cc:2668:17 (dnsdist+0x809d2c) Mutex M189 (0x55801da4cdf0) created at: #0 pthread_mutex_lock (dnsdist+0xe74f8) #1 __gthread_mutex_lock(pthread_mutex_t*) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/x86_64-linux-gnu/c++/10/bits/gthr-default.h:749:12 (dnsdist+0x80c177) #2 std::mutex::lock() /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/std_mutex.h:100:17 (dnsdist+0x80c177) #3 std::lock_guard::lock_guard(std::mutex&) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/std_mutex.h:159:19 (dnsdist+0x80c177) #4 LockGuardedHolder::LockGuardedHolder(LuaContext&, std::mutex&) /__w/pdns/pdns/pdns/dnsdistdist/./lock.hh:209:60 (dnsdist+0x80c177) #5 LockGuarded::lock() /__w/pdns/pdns/pdns/dnsdistdist/./lock.hh:289:12 (dnsdist+0x80c177) #6 main /__w/pdns/pdns/pdns/dnsdistdist/dnsdist.cc:2668:34 (dnsdist+0x809d0c) Thread T11 'dnsdist/healthC' (tid=5313, running) created by main thread at: #0 pthread_create (dnsdist+0xca21d) #1 std::thread::_M_start_thread(std::unique_ptr >, void (*)()) (libstdc++.so.6+0xcf144) #2 main /__w/pdns/pdns/pdns/dnsdistdist/dnsdist.cc:2938:12 (dnsdist+0x80b06e) Thread T21 'dnsdist/conscli' (tid=5325, finished) created by thread T5 at: #0 pthread_create (dnsdist+0xca21d) #1 std::thread::_M_start_thread(std::unique_ptr >, void (*)()) (libstdc++.so.6+0xcf144) #2 void std::__invoke_impl(std::__invoke_other, void (*&&)(int, ComboAddress), int&&, ComboAddress&&) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/invoke.h:60:14 (dnsdist+0x6c0435) #3 std::__invoke_result::type std::__invoke(void (*&&)(int, ComboAddress), int&&, ComboAddress&&) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/invoke.h:95:14 (dnsdist+0x6c0435) #4 void std::thread::_Invoker >::_M_invoke<0ul, 1ul, 2ul>(std::_Index_tuple<0ul, 1ul, 2ul>) /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/thread:264:13 (dnsdist+0x6c0435) #5 std::thread::_Invoker >::operator()() /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/thread:271:11 (dnsdist+0x6c0435) #6 std::thread::_State_impl > >::_M_run() /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/thread:215:13 (dnsdist+0x6c0435) #7 (libstdc++.so.6+0xceecf) ``` --- pdns/dnsdistdist/dnsdist-tsan.supp | 1 + 1 file changed, 1 insertion(+) diff --git a/pdns/dnsdistdist/dnsdist-tsan.supp b/pdns/dnsdistdist/dnsdist-tsan.supp index f9c1d984d642..d597a72af721 100644 --- a/pdns/dnsdistdist/dnsdist-tsan.supp +++ b/pdns/dnsdistdist/dnsdist-tsan.supp @@ -15,4 +15,5 @@ race:DownstreamState::setAuto # eventual consistency is fine race:DownstreamState::stop race:DownstreamState::submitHealthCheckResult +race:DownstreamState::healthCheckRequired race:carbonDumpThread