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

Use thread sanitizer (tsan) to check data races #452

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

stefanscherzinger
Copy link
Contributor

@stefanscherzinger stefanscherzinger commented Aug 13, 2021

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 is a quick draft to temporary add thread sanitizer (tsan) to the core of the
driver. It's not meant to stay here and shall only give an in-depth
analysis of possible data races in the code.
@stefanscherzinger stefanscherzinger marked this pull request as draft August 13, 2021 11:57
@stefanscherzinger stefanscherzinger added the help wanted Extra attention is needed label Aug 13, 2021
@github-actions
Copy link

github-actions bot commented Apr 2, 2023

This PR hasn't made any progress for quite some time and will be closed soon. Please comment if it is still relevant.

@github-actions github-actions bot added the Stale label Apr 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed Stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant