Skip to content

Test waiter leak on timeout - #1674

Merged
clalancette merged 2 commits into
clalancette/fix-immediate-shutdownfrom
test-waiter-leak-on-timeout
Jun 2, 2026
Merged

Test waiter leak on timeout#1674
clalancette merged 2 commits into
clalancette/fix-immediate-shutdownfrom
test-waiter-leak-on-timeout

Conversation

@mjcarroll

Copy link
Copy Markdown
Member

Description

Test and fix for a race condition I found in #1666

More context specifically here: #1666 (comment)

Running with the first commit (test only) and it fails. Run with fix and it passes.

Did you use Generative AI?

Assisted-by: Gemini CLI:Gemini 3.5 Flash

mjcarroll added 2 commits May 29, 2026 15:09
Signed-off-by: Michael Carroll <mjcarroll.oss@gmail.com>
Signed-off-by: Michael Carroll <mjcarroll.oss@gmail.com>
@mjcarroll
mjcarroll requested a review from clalancette May 29, 2026 20:33

@fujitatomoya fujitatomoya left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm.

a thread that added itself to _waiting_threads and then timed out never removed itself. a leaked entry makes a future wait() from another thread see the predicate satisfied prematurely. it returns True (drained) while a callback is still genuinely in flight.

Comment thread rclpy/rclpy/executors.py
Comment on lines +190 to +193
if not drained or (added_self and current not in self._executing_thread_counts):
if added_self:
self._waiting_threads.discard(current)
self._work_condition.notify_all()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit; can be simplified?

Suggested change
if not drained or (added_self and current not in self._executing_thread_counts):
if added_self:
self._waiting_threads.discard(current)
self._work_condition.notify_all()
if added_self and (not drained or current not in self._executing_thread_counts):
self._waiting_threads.discard(current)
self._work_condition.notify_all()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll do this simplification over on the other PR.

@clalancette
clalancette merged commit e532007 into clalancette/fix-immediate-shutdown Jun 2, 2026
3 checks passed
@clalancette
clalancette deleted the test-waiter-leak-on-timeout branch June 2, 2026 13:11
clalancette pushed a commit that referenced this pull request Jun 2, 2026
* Add test case for _WorkTracker waiter membership leak on timeout

Signed-off-by: Michael Carroll <mjcarroll.oss@gmail.com>

* Fix waiter membership leak in _WorkTracker.wait on timeout

Signed-off-by: Michael Carroll <mjcarroll.oss@gmail.com>

---------

Signed-off-by: Michael Carroll <mjcarroll.oss@gmail.com>
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.

3 participants