Skip to content

fix: Prevent client destruction race condition (backport #1183)#1188

Merged
bjsowa merged 1 commit intokiltedfrom
mergify/bp/kilted/pr-1183
Mar 17, 2026
Merged

fix: Prevent client destruction race condition (backport #1183)#1188
bjsowa merged 1 commit intokiltedfrom
mergify/bp/kilted/pr-1183

Conversation

@mergify
Copy link

@mergify mergify bot commented Mar 17, 2026

Public API Changes
None

Description

  1. Adds a client creation/destruction stress test to replicate the issue observed where sometimes we would see:
Exception in thread Thread-1 (spin):
Traceback (most recent call last):
  File "/usr/lib/python3.12/threading.py", line 1073, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.12/threading.py", line 1010, in run
    self._target(*self._args, **self._kwargs)
  File "/opt/ros/kilted/lib/python3.12/site-packages/rclpy/executors.py", line 374, in spin
    self.spin_once()
  File "/opt/ros/kilted/lib/python3.12/site-packages/rclpy/executors.py", line 968, in spin_once
    self._spin_once_impl(timeout_sec)
  File "/opt/ros/kilted/lib/python3.12/site-packages/rclpy/executors.py", line 951, in _spin_once_impl
    handler, entity, node = self.wait_for_ready_callbacks(
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/ros/kilted/lib/python3.12/site-packages/rclpy/executors.py", line 921, in wait_for_ready_callbacks
    return next(self._cb_iter)
           ^^^^^^^^^^^^^^^^^^^
  File "/opt/ros/kilted/lib/python3.12/site-packages/rclpy/executors.py", line 820, in _wait_for_ready_callbacks
    waitable.add_to_wait_set(wait_set)
  File "/opt/ros/kilted/lib/python3.12/site-packages/rclpy/event_handler.py", line 176, in add_to_wait_set
rclpy._rclpy_pybind11.InvalidHandle: cannot use Destroyable because destruction was requested

Note that this stress test is relatively slow, takes 20 seconds on my machine.

  1. Fixes the issue by adding the websocket protocol destruction to the executor waitset (if possible) to prevent a race condition with the executor's other tasks.

Tested on ROS2 kilted.

May be related to: #1144


This is an automatic backport of pull request #1183 done by Mergify.

* Client creation/destruction race condition stress test

* Fix race condition with client destruction

* Use ros isolated pytest (#4)

---------

Co-authored-by: Błażej Sowa <bsowa123@gmail.com>
(cherry picked from commit 5b20a2e)
@bjsowa bjsowa merged commit ffcd801 into kilted Mar 17, 2026
5 checks passed
@bjsowa bjsowa deleted the mergify/bp/kilted/pr-1183 branch March 17, 2026 10:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants