rclpy
rclpy copied to clipboard
`rcl_shutdown` is not thread-safe when used in both `signal_handler` and `Context.__exit__`.
Bug report
We found this sporadic failure with rclpy (rolling) due to the race condition while calling rcl_shutdown
.
In this issue, the conflict happens if rmw_shutdown
is slow so that rcutils_atomic_store
on Thread 1 is set after the check rcl_context_is_valid
on Thread 2. Therefore rcl_shutdown
would be called twice and cause an error.
Analysis
-
Thread 1
-
Thread 2
- InitContextManger.__exit__
- _try_shutdown
- g_default_context.try_shutdown()
- if self.__context.ok()
- Context::ok() -> rcl_context_is_valid // If this passes
- Context::shutdown() -> rcl_shutdown // , then this will run
Required Info:
- Operating System:
- Ubuntu 24.04
- Installation type:
- Docker
- Version or commit hash:
- ros-rolling
- DDS implementation:
- This bug is RMW independent. Any RMW implementation with a slow
rmw_shutdown
could lead to this issue.
- This bug is RMW independent. Any RMW implementation with a slow
- Client library (if applicable):
- Both rcl and rclpy are rolling.
- Relevant issue: #1081