Universal_Robots_ROS_Driver
Universal_Robots_ROS_Driver copied to clipboard
Use thread sanitizer (tsan) to check data races
Background
Recently, there was an issue about possible data races in the driver's hardware_interface (PR here by @AndyZe). While critical parts have been spotted, it might be reasonable to run an in-depth investigation.
Approach In recent versions, GCC has support for thread sanitizer, which seems quite capable of spotting many potential (and actual) race conditions at runtime. Clang has this feature too, but seems to be more difficult to compile-in with a ROS stack.
This PR is not actually going to be merged. Instead, it wanted to start this discussion here. Also because, I didn't manage (yet) to get meaningful output at runtime.
Compilation The ur_robot_drivers CMakeLists.txt gets some additional build flags and we link dynamically against tsan. This step already works.
Runtime analysis Unfortunately, I get segmentation faults relatively early on.
#0 0x00007ffff71bc3a6 in __sanitizer::SizeClassAllocator64LocalCache<__sanitizer::SizeClassAllocator64<__tsan::AP64> >::Allocate (class_id=2, allocator=0x7ffff7259f40 <__tsan::allocator_placeholder>, this=0x8)
at ../../../../src/libsanitizer/sanitizer_common/sanitizer_allocator_local_cache.h:33
#1 __sanitizer::CombinedAllocator<__sanitizer::SizeClassAllocator64<__tsan::AP64>, __sanitizer::LargeMmapAllocatorPtrArrayDynamic>::Allocate (this=this@entry=0x7ffff7259f40 <__tsan::allocator_placeholder>, cache=0x8, size=<optimized out>,
alignment=16) at ../../../../src/libsanitizer/sanitizer_common/sanitizer_allocator_combined.h:69
#2 0x00007ffff71ba33a in __tsan::user_alloc_internal (thr=thr@entry=0x7ffff12beb80, pc=pc@entry=140737339191347,
sz=sz@entry=24, align=align@entry=16, signal=signal@entry=true) at ../../../../src/libsanitizer/tsan/tsan_rtl.h:431
#3 0x00007ffff71ba468 in __tsan::user_alloc (thr=thr@entry=0x7ffff12beb80, pc=pc@entry=140737339191347, sz=sz@entry=24)
at ../../../../src/libsanitizer/tsan/tsan_mman.cpp:197
#4 0x00007ffff71bf044 in operator new (size=24) at ../../../../src/libsanitizer/tsan/tsan_new_delete.cpp:64
#5 0x00007ffff7ed4611 in std::vector<pollfd, std::allocator<pollfd> >::_M_default_append(unsigned long) ()
from /opt/ros/noetic/lib/libroscpp.so
#6 0x00007ffff7ed31e8 in ros::PollSet::createNativePollset() () from /opt/ros/noetic/lib/libroscpp.so
#7 0x00007ffff7ed32a1 in ros::PollSet::update(int) () from /opt/ros/noetic/lib/libroscpp.so
#8 0x00007ffff7e6529d in ros::PollManager::threadFunc() () from /opt/ros/noetic/lib/libroscpp.so
#9 0x00007ffff694143b in ?? () from /lib/x86_64-linux-gnu/libboost_thread.so.1.71.0
#10 0x00007ffff7d18609 in start_thread (arg=<optimized out>) at pthread_create.c:477
#11 0x00007ffff6cbc293 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95
Any help is highly welcome!
This PR hasn't made any progress for quite some time and will be closed soon. Please comment if it is still relevant.