langroodi / Adaptive-AUTOSAR

Adaptive Runtime AUTOSAR Linux Simulator
MIT License
386 stars 155 forks source link

Improper pointers lifetime management #9

Closed langroodi closed 2 years ago

langroodi commented 2 years ago

Describe the bug Occurrence of SEGFAULT errors are possible due to improper lifetime management of entries and options in the SD client and server.

To Reproduce Unfortunately the behavior is a bit random, and a way of reproducing is still unknown!

Expected behavior SD sever and client should be destructed properly without any SEGFAULT error.

Additional context (please complete the following information):

langroodi commented 2 years ago

One example of failure in the following unit tests:

The following tests FAILED:
     57 - SomeIpSdTest.StartScenario (SEGFAULT)

,

The following tests FAILED:
         58 - SomeIpSdTest.ClientStopScenario (SEGFAULT)

,

The following tests FAILED:
         59 - SomeIpSdTest.ServerStopScenario (SEGFAULT)

and

The following tests FAILED:
     60 - SomeIpSdTest.StopScenario (SEGFAULT)
langroodi commented 2 years ago

After converting shared_ptr to unique_ptr during f0532586aea366789e25018b03b4736264226379, still the SEGFAULT can occur.

langroodi commented 2 years ago

After 1ac136bb63acd40895362885820b4202f2236679 commit, still the issue is there:

        Start  53: SomeIpSdTest.ServerStart
 53/163 Test  #53: SomeIpSdTest.ServerStart ......................................   Passed    0.11 sec
        Start  54: SomeIpSdTest.ClientStart
 54/163 Test  #54: SomeIpSdTest.ClientStart ......................................   Passed    0.71 sec
        Start  55: SomeIpSdTest.StartScenario
 55/163 Test  #55: SomeIpSdTest.StartScenario ....................................   Passed    0.81 sec
        Start  56: SomeIpSdTest.ClientStopScenario
 56/163 Test  #56: SomeIpSdTest.ClientStopScenario ...............................***Exception: SegFault  0.89 sec
        Start  57: SomeIpSdTest.ServerStopScenario
 57/163 Test  #57: SomeIpSdTest.ServerStopScenario ...............................   Passed    2.61 sec
        Start  58: SomeIpSdTest.StopScenario
 58/163 Test  #58: SomeIpSdTest.StopScenario .....................................   Passed    2.51 sec
langroodi commented 2 years ago

Call stack of a dead-lock which finally caused a SEGFAULT error:

__gnu_cxx::__aligned_membuf<std::pair<ara::com::helper::SdClientState const, ara::com::helper::MachineState<ara::com::helper::SdClientState>*> >::_M_ptr(const __gnu_cxx::__aligned_membuf<std::pair<ara::com::helper::SdClientState const, ara::com::helper::MachineState<ara::com::helper::SdClientState>*> > * const this) (/usr/include/c++/9/ext/aligned_buffer.h:77)
std::_Rb_tree_node<std::pair<ara::com::helper::SdClientState const, ara::com::helper::MachineState<ara::com::helper::SdClientState>*> >::_M_valptr(const std::_Rb_tree_node<std::pair<ara::com::helper::SdClientState const, ara::com::helper::MachineState<ara::com::helper::SdClientState>*> > * const this) (/usr/include/c++/9/bits/stl_tree.h:239)
std::_Rb_tree<ara::com::helper::SdClientState, std::pair<ara::com::helper::SdClientState const, ara::com::helper::MachineState<ara::com::helper::SdClientState>*>, std::_Select1st<std::pair<ara::com::helper::SdClientState const, ara::com::helper::MachineState<ara::com::helper::SdClientState>*> >, std::less<ara::com::helper::SdClientState>, std::allocator<std::pair<ara::com::helper::SdClientState const, ara::com::helper::MachineState<ara::com::helper::SdClientState>*> > >::_S_key(std::_Rb_tree<ara::com::helper::SdClientState, std::pair<ara::com::helper::SdClientState const, ara::com::helper::MachineState<ara::com::helper::SdClientState>*>, std::_Select1st<std::pair<ara::com::helper::SdClientState const, ara::com::helper::MachineState<ara::com::helper::SdClientState>*> >, std::less<ara::com::helper::SdClientState>, std::allocator<std::pair<ara::com::helper::SdClientState const, ara::com::helper::MachineState<ara::com::helper::SdClientState>*> > >::_Const_Link_type __x) (/usr/include/c++/9/bits/stl_tree.h:785)
std::_Rb_tree<ara::com::helper::SdClientState, std::pair<ara::com::helper::SdClientState const, ara::com::helper::MachineState<ara::com::helper::SdClientState>*>, std::_Select1st<std::pair<ara::com::helper::SdClientState const, ara::com::helper::MachineState<ara::com::helper::SdClientState>*> >, std::less<ara::com::helper::SdClientState>, std::allocator<std::pair<ara::com::helper::SdClientState const, ara::com::helper::MachineState<ara::com::helper::SdClientState>*> > >::_M_lower_bound(std::_Rb_tree<ara::com::helper::SdClientState, std::pair<ara::com::helper::SdClientState const, ara::com::helper::MachineState<ara::com::helper::SdClientState>*>, std::_Select1st<std::pair<ara::com::helper::SdClientState const, ara::com::helper::MachineState<ara::com::helper::SdClientState>*> >, std::less<ara::com::helper::SdClientState>, std::allocator<std::pair<ara::com::helper::SdClientState const, ara::com::helper::MachineState<ara::com::helper::SdClientState>*> > > * const this, std::_Rb_tree<ara::com::helper::SdClientState, std::pair<ara::com::helper::SdClientState const, ara::com::helper::MachineState<ara::com::helper::SdClientState>*>, std::_Select1st<std::pair<ara::com::helper::SdClientState const, ara::com::helper::MachineState<ara::com::helper::SdClientState>*> >, std::less<ara::com::helper::SdClientState>, std::allocator<std::pair<ara::com::helper::SdClientState const, ara::com::helper::MachineState<ara::com::helper::SdClientState>*> > >::_Link_type __x, std::_Rb_tree<ara::com::helper::SdClientState, std::pair<ara::com::helper::SdClientState const, ara::com::helper::MachineState<ara::com::helper::SdClientState>*>, std::_Select1st<std::pair<ara::com::helper::SdClientState const, ara::com::helper::MachineState<ara::com::helper::SdClientState>*> >, std::less<ara::com::helper::SdClientState>, std::allocator<std::pair<ara::com::helper::SdClientState const, ara::com::helper::MachineState<ara::com::helper::SdClientState>*> > >::_Base_ptr __y, const ara::com::helper::SdClientState & __k) (/usr/include/c++/9/bits/stl_tree.h:1929)
std::_Rb_tree<ara::com::helper::SdClientState, std::pair<ara::com::helper::SdClientState const, ara::com::helper::MachineState<ara::com::helper::SdClientState>*>, std::_Select1st<std::pair<ara::com::helper::SdClientState const, ara::com::helper::MachineState<ara::com::helper::SdClientState>*> >, std::less<ara::com::helper::SdClientState>, std::allocator<std::pair<ara::com::helper::SdClientState const, ara::com::helper::MachineState<ara::com::helper::SdClientState>*> > >::lower_bound(std::_Rb_tree<ara::com::helper::SdClientState, std::pair<ara::com::helper::SdClientState const, ara::com::helper::MachineState<ara::com::helper::SdClientState>*>, std::_Select1st<std::pair<ara::com::helper::SdClientState const, ara::com::helper::MachineState<ara::com::helper::SdClientState>*> >, std::less<ara::com::helper::SdClientState>, std::allocator<std::pair<ara::com::helper::SdClientState const, ara::com::helper::MachineState<ara::com::helper::SdClientState>*> > > * const this, const std::_Rb_tree<ara::com::helper::SdClientState, std::pair<ara::com::helper::SdClientState const, ara::com::helper::MachineState<ara::com::helper::SdClientState>*>, std::_Select1st<std::pair<ara::com::helper::SdClientState const, ara::com::helper::MachineState<ara::com::helper::SdClientState>*> >, std::less<ara::com::helper::SdClientState>, std::allocator<std::pair<ara::com::helper::SdClientState const, ara::com::helper::MachineState<ara::com::helper::SdClientState>*> > >::key_type & __k) (/usr/include/c++/9/bits/stl_tree.h:1282)
std::map<ara::com::helper::SdClientState, ara::com::helper::MachineState<ara::com::helper::SdClientState>*, std::less<ara::com::helper::SdClientState>, std::allocator<std::pair<ara::com::helper::SdClientState const, ara::com::helper::MachineState<ara::com::helper::SdClientState>*> > >::lower_bound(std::map<ara::com::helper::SdClientState, ara::com::helper::MachineState<ara::com::helper::SdClientState>*, std::less<ara::com::helper::SdClientState>, std::allocator<std::pair<ara::com::helper::SdClientState const, ara::com::helper::MachineState<ara::com::helper::SdClientState>*> > > * const this, const std::map<ara::com::helper::SdClientState, ara::com::helper::MachineState<ara::com::helper::SdClientState>*, std::less<ara::com::helper::SdClientState>, std::allocator<std::pair<ara::com::helper::SdClientState const, ara::com::helper::MachineState<ara::com::helper::SdClientState>*> > >::key_type & __x) (/usr/include/c++/9/bits/stl_map.h:1258)
std::map<ara::com::helper::SdClientState, ara::com::helper::MachineState<ara::com::helper::SdClientState>*, std::less<ara::com::helper::SdClientState>, std::allocator<std::pair<ara::com::helper::SdClientState const, ara::com::helper::MachineState<ara::com::helper::SdClientState>*> > >::at(std::map<ara::com::helper::SdClientState, ara::com::helper::MachineState<ara::com::helper::SdClientState>*, std::less<ara::com::helper::SdClientState>, std::allocator<std::pair<ara::com::helper::SdClientState const, ara::com::helper::MachineState<ara::com::helper::SdClientState>*> > > * const this, const std::map<ara::com::helper::SdClientState, ara::com::helper::MachineState<ara::com::helper::SdClientState>*, std::less<ara::com::helper::SdClientState>, std::allocator<std::pair<ara::com::helper::SdClientState const, ara::com::helper::MachineState<ara::com::helper::SdClientState>*> > >::key_type & __k) (/usr/include/c++/9/bits/stl_map.h:537)
ara::com::helper::FiniteStateMachine<ara::com::helper::SdClientState>::Transit(ara::com::helper::FiniteStateMachine<ara::com::helper::SdClientState> * const this, ara::com::helper::SdClientState previousState, ara::com::helper::SdClientState nextState) (~/Adaptive-AUTOSAR/src/ara/com/helper/finite_state_machine.h:67)
ara::com::helper::MachineState<ara::com::helper::SdClientState>::Transit(ara::com::helper::MachineState<ara::com::helper::SdClientState> * const this, ara::com::helper::SdClientState nextState) (~/Adaptive-AUTOSAR/src/ara/com/helper/machine_state.h:64)
ara::com::someip::sd::fsm::ServiceNotseenState::Activate(ara::com::someip::sd::fsm::ServiceNotseenState * const this, ara::com::helper::SdClientState previousState) (~/Adaptive-AUTOSAR/src/ara/com/someip/sd/fsm/service_notseen_state.cpp:33)
ara::com::helper::FiniteStateMachine<ara::com::helper::SdClientState>::Transit(ara::com::helper::FiniteStateMachine<ara::com::helper::SdClientState> * const this, ara::com::helper::SdClientState previousState, ara::com::helper::SdClientState nextState) (~/Adaptive-AUTOSAR/src/ara/com/helper/finite_state_machine.h:69)
ara::com::helper::MachineState<ara::com::helper::SdClientState>::Transit(ara::com::helper::MachineState<ara::com::helper::SdClientState> * const this, ara::com::helper::SdClientState nextState) (~/Adaptive-AUTOSAR/src/ara/com/helper/machine_state.h:64)
ara::com::someip::sd::fsm::ServiceNotseenState::Activate(ara::com::someip::sd::fsm::ServiceNotseenState * const this, ara::com::helper::SdClientState previousState) (~/Adaptive-AUTOSAR/src/ara/com/someip/sd/fsm/service_notseen_state.cpp:33)
ara::com::helper::FiniteStateMachine<ara::com::helper::SdClientState>::Transit(ara::com::helper::FiniteStateMachine<ara::com::helper::SdClientState> * const this, ara::com::helper::SdClientState previousState, ara::com::helper::SdClientState nextState) (~/Adaptive-AUTOSAR/src/ara/com/helper/finite_state_machine.h:69)
ara::com::helper::MachineState<ara::com::helper::SdClientState>::Transit(ara::com::helper::MachineState<ara::com::helper::SdClientState> * const this, ara::com::helper::SdClientState nextState) (~/Adaptive-AUTOSAR/src/ara/com/helper/machine_state.h:64)
ara::com::someip::sd::fsm::ServiceNotseenState::Activate(ara::com::someip::sd::fsm::ServiceNotseenState * const this, ara::com::helper::SdClientState previousState) (~/Adaptive-AUTOSAR/src/ara/com/someip/sd/fsm/service_notseen_state.cpp:33)
ara::com::helper::FiniteStateMachine<ara::com::helper::SdClientState>::Transit(ara::com::helper::FiniteStateMachine<ara::com::helper::SdClientState> * const this, ara::com::helper::SdClientState previousState, ara::com::helper::SdClientState nextState) (~/Adaptive-AUTOSAR/src/ara/com/helper/finite_state_machine.h:69)
ara::com::helper::MachineState<ara::com::helper::SdClientState>::Transit(ara::com::helper::MachineState<ara::com::helper::SdClientState> * const this, ara::com::helper::SdClientState nextState) (~/Adaptive-AUTOSAR/src/ara/com/helper/machine_state.h:64)
ara::com::someip::sd::fsm::ServiceNotseenState::Activate(ara::com::someip::sd::fsm::ServiceNotseenState * const this, ara::com::helper::SdClientState previousState) (~/Adaptive-AUTOSAR/src/ara/com/someip/sd/fsm/service_notseen_state.cpp:33)
ara::com::helper::FiniteStateMachine<ara::com::helper::SdClientState>::Transit(ara::com::helper::FiniteStateMachine<ara::com::helper::SdClientState> * const this, ara::com::helper::SdClientState previousState, ara::com::helper::SdClientState nextState) (~/Adaptive-AUTOSAR/src/ara/com/helper/finite_state_machine.h:69)
langroodi commented 2 years ago

ServerStopScenario SEGFAULT error stack trace after f14b6a8e16e4c3d26ee94646dd76570e8619507a commit:

[Unknown/Just-In-Time compiled code] (Unknown Source:0)
std::_Destroy<ara::com::someip::sd::SomeIpSdMessage>(ara::com::someip::sd::SomeIpSdMessage * __pointer) (/usr/include/c++/9/bits/stl_construct.h:98)
std::_Destroy_aux<false>::__destroy<ara::com::someip::sd::SomeIpSdMessage*>(ara::com::someip::sd::SomeIpSdMessage * __first, ara::com::someip::sd::SomeIpSdMessage * __last) (/usr/include/c++/9/bits/stl_construct.h:108)
std::_Destroy<ara::com::someip::sd::SomeIpSdMessage*>(ara::com::someip::sd::SomeIpSdMessage * __first, ara::com::someip::sd::SomeIpSdMessage * __last) (/usr/include/c++/9/bits/stl_construct.h:137)
std::_Destroy<ara::com::someip::sd::SomeIpSdMessage*, ara::com::someip::sd::SomeIpSdMessage>(ara::com::someip::sd::SomeIpSdMessage * __first, ara::com::someip::sd::SomeIpSdMessage * __last) (/usr/include/c++/9/bits/stl_construct.h:206)
std::deque<ara::com::someip::sd::SomeIpSdMessage, std::allocator<ara::com::someip::sd::SomeIpSdMessage> >::_M_destroy_data_aux(std::deque<ara::com::someip::sd::SomeIpSdMessage, std::allocator<ara::com::someip::sd::SomeIpSdMessage> > * const this, std::deque<ara::com::someip::sd::SomeIpSdMessage, std::allocator<ara::com::someip::sd::SomeIpSdMessage> >::iterator __first, std::deque<ara::com::someip::sd::SomeIpSdMessage, std::allocator<ara::com::someip::sd::SomeIpSdMessage> >::iterator __last) (/usr/include/c++/9/bits/deque.tcc:870)
std::deque<ara::com::someip::sd::SomeIpSdMessage, std::allocator<ara::com::someip::sd::SomeIpSdMessage> >::_M_destroy_data(std::deque<ara::com::someip::sd::SomeIpSdMessage, std::allocator<ara::com::someip::sd::SomeIpSdMessage> > * const this, std::deque<ara::com::someip::sd::SomeIpSdMessage, std::allocator<ara::com::someip::sd::SomeIpSdMessage> >::iterator __first, std::deque<ara::com::someip::sd::SomeIpSdMessage, std::allocator<ara::com::someip::sd::SomeIpSdMessage> >::iterator __last) (/usr/include/c++/9/bits/stl_deque.h:2117)
std::deque<ara::com::someip::sd::SomeIpSdMessage, std::allocator<ara::com::someip::sd::SomeIpSdMessage> >::~deque(std::deque<ara::com::someip::sd::SomeIpSdMessage, std::allocator<ara::com::someip::sd::SomeIpSdMessage> > * const this) (/usr/include/c++/9/bits/stl_deque.h:1072)
std::queue<ara::com::someip::sd::SomeIpSdMessage, std::deque<ara::com::someip::sd::SomeIpSdMessage, std::allocator<ara::com::someip::sd::SomeIpSdMessage> > >::~queue(std::queue<ara::com::someip::sd::SomeIpSdMessage, std::deque<ara::com::someip::sd::SomeIpSdMessage, std::allocator<ara::com::someip::sd::SomeIpSdMessage> > > * const this) (/usr/include/c++/9/bits/stl_queue.h:96)
ara::com::someip::sd::SomeIpSdServer::~SomeIpSdServer(ara::com::someip::sd::SomeIpSdServer * const this) (~/Adaptive-AUTOSAR/src/ara/com/someip/sd/someip_sd_server.cpp:175)
ara::com::someip::sd::SomeIpSdTest::~SomeIpSdTest(ara::com::someip::sd::SomeIpSdTest * const this) (~/Adaptive-AUTOSAR/test/ara/com/someip/sd/someip_sd_test.cpp:14)
ara::com::someip::sd::SomeIpSdTest_ServerStopScenario_Test::~SomeIpSdTest_ServerStopScenario_Test(ara::com::someip::sd::SomeIpSdTest_ServerStopScenario_Test * const this) (~/Adaptive-AUTOSAR/test/ara/com/someip/sd/someip_sd_test.cpp:117)
ara::com::someip::sd::SomeIpSdTest_ServerStopScenario_Test::~SomeIpSdTest_ServerStopScenario_Test(ara::com::someip::sd::SomeIpSdTest_ServerStopScenario_Test * const this) (~/Adaptive-AUTOSAR/test/ara/com/someip/sd/someip_sd_test.cpp:117)
testing::Test::DeleteSelf_(testing::Test * const this) (~/Adaptive-AUTOSAR/build/_deps/googletest-src/googletest/include/gtest/gtest.h:506)
testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void>(testing::Test * object, void (testing::Test::*)(testing::Test * const) method, const char * location) (~/Adaptive-AUTOSAR/build/_deps/googletest-src/googletest/src/gtest.cc:2631)
testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test * object, void (testing::Test::*)(testing::Test * const) method, const char * location) (~/Adaptive-AUTOSAR/build/_deps/googletest-src/googletest/src/gtest.cc:2667)
testing::TestInfo::Run(testing::TestInfo * const this) (~/Adaptive-AUTOSAR/build/_deps/googletest-src/googletest/src/gtest.cc:2891)
testing::TestSuite::Run(testing::TestSuite * const this) (~/Adaptive-AUTOSAR/build/_deps/googletest-src/googletest/src/gtest.cc:3039)
testing::internal::UnitTestImpl::RunAllTests(testing::internal::UnitTestImpl * const this) (~/Adaptive-AUTOSAR/build/_deps/googletest-src/googletest/src/gtest.cc:5898)
testing::internal::HandleSehExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl * object, bool (testing::internal::UnitTestImpl::*)(testing::internal::UnitTestImpl * const) method, const char * location) (~/Adaptive-AUTOSAR/build/_deps/googletest-src/googletest/src/gtest.cc:2631)
testing::internal::HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl * object, bool (testing::internal::UnitTestImpl::*)(testing::internal::UnitTestImpl * const) method, const char * location) (~/Adaptive-AUTOSAR/build/_deps/googletest-src/googletest/src/gtest.cc:2667)
testing::UnitTest::Run(testing::UnitTest * const this) (~/Adaptive-AUTOSAR/build/_deps/googletest-src/googletest/src/gtest.cc:5465)
RUN_ALL_TESTS() (~/Adaptive-AUTOSAR/build/_deps/googletest-src/googletest/include/gtest/gtest.h:2495)
main(int argc, char ** argv) (~/Adaptive-AUTOSAR/build/_deps/googletest-src/googletest/src/gtest_main.cc:52)