Fix a bug on adding unnecessary done callback of future while repeatedly calling spin_until_future_complete (backport #1374) #1530
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Address a bug while investigating #1371
If write action client code like below,
In spin_until_future_complete(), a callback is added to the done callback of future. And next spin_once_until_future_complete() will be called continuously.
rclpy/rclpy/rclpy/executors.py
Lines 314 to 332 in a09a031
Each time spin_once_until_future_complete() is called, the same callback is added to the future's done callback.
rclpy/rclpy/rclpy/executors.py
Lines 855 to 861 in a09a031
This way, the future's done callbacks keep accumulating.
When a future is completed (calls set_result()), _schedule_or_invoke_done_callbacks() is called.
In this function, it creates a Task for each done callback, which leads to many unnecessary Tasks being created and consuming more and more memory.
rclpy/rclpy/rclpy/task.py
Lines 150 to 153 in a09a031
So this PR is to remove the code that adds unnecessary done callbacks.
This is an automatic backport of pull request #1374 done by Mergify.