-
Notifications
You must be signed in to change notification settings - Fork 260
Fix a bug on adding unnecessary done callback of future while repeatedly calling spin_until_future_complete #1374
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix a bug on adding unnecessary done callback of future while repeatedly calling spin_until_future_complete #1374
Conversation
fujitatomoya
left a comment
There was a problem hiding this 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.
@Barry-Xu-2018 btw could you check if this PR fixes the memory leak issue #1371
|
In my environment, the action client memory still increases a bit, but it's much less than before. |
… spin_until_future_complete Signed-off-by: Barry Xu <[email protected]>
5193156 to
d495a94
Compare
|
Only update commit description in d495a94 |
|
@clalancette @sloretz @ahcorde could either of you review this? |
… spin_until_future_complete (ros2#1374) Signed-off-by: Barry Xu <[email protected]>
|
Can this be backported? I just tripped over it in Jazzy. |
|
@Mergifyio backport jazzy |
✅ Backports have been created
|
… spin_until_future_complete (#1374) Signed-off-by: Barry Xu <[email protected]> (cherry picked from commit c009b0d) # Conflicts: # rclpy/rclpy/executors.py
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.