Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible race in CGlobals #1474

Open
KerstinKeller opened this issue Mar 18, 2024 · 0 comments
Open

Possible race in CGlobals #1474

KerstinKeller opened this issue Mar 18, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@KerstinKeller
Copy link
Contributor

KerstinKeller commented Mar 18, 2024

Problem Description

During eCAL initialization, a datarace may occur.

bool initialized;
unsigned int components;

Both initialized and components are regular variables.
They are set in Initialize()

initialized = true;
components |= components_;
and accessed via
GetComponents:
unsigned int GetComponents() const { return(components); };

So neither are they atomic, nor are they protected my a mutex. this will lead to a datarace when the CRegistrationProvider asks for GetComponents in the RegisterSendThread.

How to reproduce

Build with -fsanitize=thread.

How did you get eCAL?

I don't know

Environment

==================

WARNING: ThreadSanitizer: data race (pid=2073552)
  Write of size 4 at 0x7b1c00000004 by main thread:
    #0 eCAL::CGlobals::Initialize(unsigned int, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >*) /home/kerstin/SourceCode/github/ecal/ecal/core/src/ecal_globals.cpp:256 (libecal_core.so.6+0x6518ef)
    #1 eCAL::Initialize(int, char**, char const*, unsigned int) /home/kerstin/SourceCode/github/ecal/ecal/core/src/ecal.cpp:184 (libecal_core.so.6+0x63047d)
    #2 Util_ParallelUtilFunctions_Test::TestBody() /home/kerstin/SourceCode/github/ecal/ecal/tests/cpp/util_test/src/util_test.cpp:204 (ecal_test_util-6.0.0+0x224e2)
    #3 void testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) /opt/data/jenkins/workspace/conan_data/gtest/1.13.0/ild/stable/build/e8eb4ed82bbc9189506c20193a1c23fffde1ee15/googletest/src/gtest.cc:2621 (ecal_test_util-6.0.0+0x6f4d1)

  Previous read of size 4 at 0x7b1c00000004 by thread T2:
    #0 eCAL::CGlobals::GetComponents() const /home/kerstin/SourceCode/github/ecal/ecal/core/src/ecal_globals.h:67 (libecal_core.so.6+0x5a7ed8)
    #1 eCAL::CRegistrationProvider::RegisterProcess() /home/kerstin/SourceCode/github/ecal/ecal/core/src/registration/ecal_registration_provider.cpp:353 (libecal_core.so.6+0x5a627b)
    #2 eCAL::CRegistrationProvider::RegisterSendThread() /home/kerstin/SourceCode/github/ecal/ecal/core/src/registration/ecal_registration_provider.cpp:550 (libecal_core.so.6+0x5a7386)
    #3 void std::__invoke_impl<void, void (eCAL::CRegistrationProvider::*&)(), eCAL::CRegistrationProvider*&>(std::__invoke_memfun_deref, void (eCAL::CRegistrationProvider::*&)(), eCAL::CRegistrationProvider*&) /usr/include/c++/9/bits/invoke.h:73 (libecal_core.so.6+0x5b253c)
    #4 std::__invoke_result<void (eCAL::CRegistrationProvider::*&)(), eCAL::CRegistrationProvider*&>::type std::__invoke<void (eCAL::CRegistrationProvider::*&)(), eCAL::CRegistrationProvider*&>(void (eCAL::CRegistrationProvider::*&)(), eCAL::CRegistrationProvider*&) /usr/include/c++/9/bits/invoke.h:95 (libecal_core.so.6+0x5b240b)
    #5 void std::_Bind<void (eCAL::CRegistrationProvider::*(eCAL::CRegistrationProvider*))()>::__call<void, , 0ul>(std::tuple<>&&, std::_Index_tuple<0ul>) <null> (libecal_core.so.6+0x5b22bf)
    #6 void std::_Bind<void (eCAL::CRegistrationProvider::*(eCAL::CRegistrationProvider*))()>::operator()<, void>() /usr/include/c++/9/functional:484 (libecal_core.so.6+0x5b2085)
    #7 std::_Function_handler<void (), std::_Bind<void (eCAL::CRegistrationProvider::*(eCAL::CRegistrationProvider*))()> >::_M_invoke(std::_Any_data const&) /usr/include/c++/9/bits/std_function.h:300 (libecal_core.so.6+0x5b1e3a)
    #8 std::function<void ()>::operator()() const /usr/include/c++/9/bits/std_function.h:688 (libecal_core.so.6+0x43312e)
    #9 void eCAL::CCallbackThread::callbackFunction<std::chrono::duration<long, std::ratio<1l, 1000l> > >(std::chrono::duration<long, std::ratio<1l, 1000l> >) /home/kerstin/SourceCode/github/ecal/ecal/core/src/util/ecal_thread.h:118 (libecal_core.so.6+0x4bf978)
    #10 void std::__invoke_impl<void, void (eCAL::CCallbackThread::*)(std::chrono::duration<long, std::ratio<1l, 1000l> >), eCAL::CCallbackThread*, std::chrono::duration<long, std::ratio<1l, 1000l> > >(std::__invoke_memfun_deref, void (eCAL::CCallbackThread::*&&)(std::chrono::duration<long, std::ratio<1l, 1000l> >), eCAL::CCallbackThread*&&, std::chrono::duration<long, std::ratio<1l, 1000l> >&&) /usr/include/c++/9/bits/invoke.h:73 (libecal_core.so.6+0x4c6104)
    #11 std::__invoke_result<void (eCAL::CCallbackThread::*)(std::chrono::duration<long, std::ratio<1l, 1000l> >), eCAL::CCallbackThread*, std::chrono::duration<long, std::ratio<1l, 1000l> > >::type std::__invoke<void (eCAL::CCallbackThread::*)(std::chrono::duration<long, std::ratio<1l, 1000l> >), eCAL::CCallbackThread*, std::chrono::duration<long, std::ratio<1l, 1000l> > >(void (eCAL::CCallbackThread::*&&)(std::chrono::duration<long, std::ratio<1l, 1000l> >), eCAL::CCallbackThread*&&, std::chrono::duration<long, std::ratio<1l, 1000l> >&&) /usr/include/c++/9/bits/invoke.h:95 (libecal_core.so.6+0x4c5f34)
    #12 void std::thread::_Invoker<std::tuple<void (eCAL::CCallbackThread::*)(std::chrono::duration<long, std::ratio<1l, 1000l> >), eCAL::CCallbackThread*, std::chrono::duration<long, std::ratio<1l, 1000l> > > >::_M_invoke<0ul, 1ul, 2ul>(std::_Index_tuple<0ul, 1ul, 2ul>) /usr/include/c++/9/thread:244 (libecal_core.so.6+0x4c5dc0)
    #13 std::thread::_Invoker<std::tuple<void (eCAL::CCallbackThread::*)(std::chrono::duration<long, std::ratio<1l, 1000l> >), eCAL::CCallbackThread*, std::chrono::duration<long, std::ratio<1l, 1000l> > > >::operator()() /usr/include/c++/9/thread:251 (libecal_core.so.6+0x4c5c69)
    #14 std::thread::_State_impl<std::thread::_Invoker<std::tuple<void (eCAL::CCallbackThread::*)(std::chrono::duration<long, std::ratio<1l, 1000l> >), eCAL::CCallbackThread*, std::chrono::duration<long, std::ratio<1l, 1000l> > > > >::_M_run() /usr/include/c++/9/thread:195 (libecal_core.so.6+0x4c5b1c)
    #15 <null> <null> (libstdc++.so.6+0xd6df3)

  Location is heap block of size 112 at 0x7b1c00000000 allocated by main thread:
    #0 operator new(unsigned long) ../../../../src/libsanitizer/tsan/tsan_new_delete.cpp:64 (libtsan.so.0+0x8bc72)
    #1 eCAL::Initialize(int, char**, char const*, unsigned int) /home/kerstin/SourceCode/github/ecal/ecal/core/src/ecal.cpp:149 (libecal_core.so.6+0x6302b4)
    #2 Util_ParallelUtilFunctions_Test::TestBody() /home/kerstin/SourceCode/github/ecal/ecal/tests/cpp/util_test/src/util_test.cpp:204 (ecal_test_util-6.0.0+0x224e2)
    #3 void testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) /opt/data/jenkins/workspace/conan_data/gtest/1.13.0/ild/stable/build/e8eb4ed82bbc9189506c20193a1c23fffde1ee15/googletest/src/gtest.cc:2621 (ecal_test_util-6.0.0+0x6f4d1)

  Thread T2 (tid=2073558, running) created by main thread at:
    #0 pthread_create ../../../../src/libsanitizer/tsan/tsan_interceptors_posix.cpp:962 (libtsan.so.0+0x5ea79)
    #1 std::thread::_M_start_thread(std::unique_ptr<std::thread::_State, std::default_delete<std::thread::_State> >, void (*)()) <null> (libstdc++.so.6+0xd70c9)
    #2 void eCAL::CCallbackThread::start<std::chrono::duration<long, std::ratio<1l, 1000l> > >(std::chrono::duration<long, std::ratio<1l, 1000l> >) /home/kerstin/SourceCode/github/ecal/ecal/core/src/util/ecal_thread.h:64 (libecal_core.so.6+0x4bed2a)
    #3 eCAL::CRegistrationProvider::Create(bool, bool, bool) /home/kerstin/SourceCode/github/ecal/ecal/core/src/registration/ecal_registration_provider.cpp:146 (libecal_core.so.6+0x5a52d1)
    #4 eCAL::CGlobals::Initialize(unsigned int, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >*) /home/kerstin/SourceCode/github/ecal/ecal/core/src/ecal_globals.cpp:232 (libecal_core.so.6+0x651629)
    #5 eCAL::Initialize(int, char**, char const*, unsigned int) /home/kerstin/SourceCode/github/ecal/ecal/core/src/ecal.cpp:184 (libecal_core.so.6+0x63047d)
    #6 Util_ParallelUtilFunctions_Test::TestBody() /home/kerstin/SourceCode/github/ecal/ecal/tests/cpp/util_test/src/util_test.cpp:204 (ecal_test_util-6.0.0+0x224e2)
    #7 void testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) /opt/data/jenkins/workspace/conan_data/gtest/1.13.0/ild/stable/build/e8eb4ed82bbc9189506c20193a1c23fffde1ee15/googletest/src/gtest.cc:2621 (ecal_test_util-6.0.0+0x6f4d1)

SUMMARY: ThreadSanitizer: data race /home/kerstin/SourceCode/github/ecal/ecal/core/src/ecal_globals.cpp:256 in eCAL::CGlobals::Initialize(unsigned int, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >*)

==================

eCAL System Information

No response

@KerstinKeller KerstinKeller added the bug Something isn't working label Mar 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant