-
Notifications
You must be signed in to change notification settings - Fork 507
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 memory leak on service call #774
Conversation
I can confirm that I have observed this same issue with rosbridge gradually consuming a lot of CPU and memory after running for several hours, causing other ROS nodes to slow down, and this PR appears to fix the issue. |
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.
This does not work if you have multiple services with the same service type. I would propose to simply destroy the service client after the call.
if service_class in clients: | ||
client = clients[service_class] | ||
else: | ||
client = node_handle.create_client(service_class, service) | ||
clients[service_class] = client |
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.
This does not work if you have multiple services with the same service type but different names. Let's say you have two identical services under a different namespace:
/robot_1/do_something
/robot_2/do_something
You will only call one of these services (the one you called first), as they have the same service type.
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.
I'll consider it, thanks!
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.
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.
@achim-k |
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.
I think the simplest solution would be to destroy the service client again after use. Would that solution be ok with you?
|
||
result = client.call(inst) | ||
|
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.
node_handle.destroy_client(client) |
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.
No.
And I know that node_handle.destroy_client(client) does not free all memory.
Adding this code, memory leak issue is not solved.
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.
My first commit was this, but I found it didn't release all the memory.
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.
releasing resources by node_handle.destroy_client(client)
is rclpy responsibility, so I'll change this PR, and I'll also submit to fix this issue to rclpy repo.
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.
If you create a rclpy
issue / PR, could you add a link here? Thanks!
@achim-k PR has been updated, please have a check! |
|
||
result = client.call(inst) | ||
|
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.
If you create a rclpy
issue / PR, could you add a link here? Thanks!
@achim-k The isue: ros2/rclpy#1034 has been created. |
Public API Changes
None
Description
A memory leak occurs each time a service call is invoked from rosbridge client.
This means calling service call from the client leads to resource exhaustion.
This fixes #772
#772