Skip to content

Bugfix: executor doesn't propagate exception from task that awaited a future#1643

Merged
mjcarroll merged 5 commits into
ros2:rollingfrom
nadavelkabets:bugfix/task-raise-after-await
Apr 18, 2026
Merged

Bugfix: executor doesn't propagate exception from task that awaited a future#1643
mjcarroll merged 5 commits into
ros2:rollingfrom
nadavelkabets:bugfix/task-raise-after-await

Conversation

@nadavelkabets
Copy link
Copy Markdown
Contributor

@nadavelkabets nadavelkabets commented Apr 7, 2026

Fixes #1642

Changes

A task now registers itself on the awaited future via new Future._add_waiting_task.
The executor then dispatches the same Task object and sees its exception through handler.exception() as intended.

  • Future._callbacks now holds Union[Callable, Task]
  • _schedule_or_invoke_done_callbacks handles Task entries through executor._call_task_in_next_spin.
  • _wait_for_ready_callbacks skips tasks that were cancelled or completed between being queued and being popped.
  • A warnings.warn fires if a waiting Task is dropped because the executor weakref could not be resolved.

Signed-off-by: Nadav Elkabets <elnadav12@gmail.com>
Signed-off-by: Nadav Elkabets <elnadav12@gmail.com>
Signed-off-by: Nadav Elkabets <elnadav12@gmail.com>
Signed-off-by: Nadav Elkabets <elnadav12@gmail.com>
Signed-off-by: Nadav Elkabets <elnadav12@gmail.com>
Copy link
Copy Markdown
Collaborator

@fujitatomoya fujitatomoya left a comment

Choose a reason for hiding this comment

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

i think that the approach of preserving task identity rather than wrapping in a new task is the right call. almost lgtm, with just one minor suggestion.

Comment thread rclpy/rclpy/task.py
Copy link
Copy Markdown
Collaborator

@fujitatomoya fujitatomoya left a comment

Choose a reason for hiding this comment

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

lgtm with green CI.

@fujitatomoya
Copy link
Copy Markdown
Collaborator

Pulls: #1643
Gist: https://gist.githubusercontent.com/fujitatomoya/304d03354c28f17e75b36dec7465ed9c/raw/364b136f9e5a7268dd0d7017890a230f6bb89273/ros2.repos
BUILD args: --packages-above-and-dependencies rclpy
TEST args: --packages-above rclpy
ROS Distro: rolling
Job: ci_launcher
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/18897

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Linux-rhel Build Status
  • Windows Build Status

@nadavelkabets
Copy link
Copy Markdown
Contributor Author

@fujitatomoya could you run windows again?

@fujitatomoya
Copy link
Copy Markdown
Collaborator

  • Linux-aarch64 Build Status
  • Windows Build Status

@mjcarroll
Copy link
Copy Markdown
Member

  • Linux-aarch64 Build Status
  • Windows Build Status

@mjcarroll mjcarroll merged commit aac0ebb into ros2:rolling Apr 18, 2026
3 of 4 checks passed
@mjcarroll
Copy link
Copy Markdown
Member

@Mergifyio backport kilted jazzy humble

@mergify
Copy link
Copy Markdown
Contributor

mergify Bot commented Apr 18, 2026

backport kilted jazzy humble

✅ Backports have been created

Details

Cherry-pick of aac0ebb has failed:

On branch mergify/bp/jazzy/pr-1643
Your branch is up to date with 'origin/jazzy'.

You are currently cherry-picking commit aac0ebb.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	modified:   rclpy/rclpy/executors.py

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   rclpy/rclpy/task.py
	both modified:   rclpy/test/test_executor.py

To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally

Cherry-pick of aac0ebb has failed:

On branch mergify/bp/humble/pr-1643
Your branch is up to date with 'origin/humble'.

You are currently cherry-picking commit aac0ebb.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	modified:   rclpy/rclpy/executors.py

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   rclpy/rclpy/task.py
	both modified:   rclpy/test/test_executor.py

To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally

mergify Bot pushed a commit that referenced this pull request Apr 18, 2026
… future (#1643)

* Schedule the original task when task awaits a future

Signed-off-by: Nadav Elkabets <elnadav12@gmail.com>

* Add MultiThreadedExecutor to test

Signed-off-by: Nadav Elkabets <elnadav12@gmail.com>

* Add tests for awaiting a done future and task cancellation during await

Signed-off-by: Nadav Elkabets <elnadav12@gmail.com>

* Removed unused variable

Signed-off-by: Nadav Elkabets <elnadav12@gmail.com>

---------

Signed-off-by: Nadav Elkabets <elnadav12@gmail.com>
(cherry picked from commit aac0ebb)
mergify Bot pushed a commit that referenced this pull request Apr 18, 2026
… future (#1643)

* Schedule the original task when task awaits a future

Signed-off-by: Nadav Elkabets <elnadav12@gmail.com>

* Add MultiThreadedExecutor to test

Signed-off-by: Nadav Elkabets <elnadav12@gmail.com>

* Add tests for awaiting a done future and task cancellation during await

Signed-off-by: Nadav Elkabets <elnadav12@gmail.com>

* Removed unused variable

Signed-off-by: Nadav Elkabets <elnadav12@gmail.com>

---------

Signed-off-by: Nadav Elkabets <elnadav12@gmail.com>
(cherry picked from commit aac0ebb)

# Conflicts:
#	rclpy/rclpy/task.py
#	rclpy/test/test_executor.py
mergify Bot pushed a commit that referenced this pull request Apr 18, 2026
… future (#1643)

* Schedule the original task when task awaits a future

Signed-off-by: Nadav Elkabets <elnadav12@gmail.com>

* Add MultiThreadedExecutor to test

Signed-off-by: Nadav Elkabets <elnadav12@gmail.com>

* Add tests for awaiting a done future and task cancellation during await

Signed-off-by: Nadav Elkabets <elnadav12@gmail.com>

* Removed unused variable

Signed-off-by: Nadav Elkabets <elnadav12@gmail.com>

---------

Signed-off-by: Nadav Elkabets <elnadav12@gmail.com>
(cherry picked from commit aac0ebb)

# Conflicts:
#	rclpy/rclpy/task.py
#	rclpy/test/test_executor.py
mjcarroll added a commit that referenced this pull request Apr 29, 2026
mjcarroll added a commit that referenced this pull request Apr 29, 2026
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.

SingleThreadedExecutor silently swallows exception when coroutine raises after awaiting a Future

3 participants