Memory leak in client when using python wrapper to send request to service
See original GitHub issueI found this problem in latest Galactic release, it is simple to reproduce, write a simple service(C++) and a client (Python), memory leak will definitly happen. It will not happen when using C++ in client.
- Data struct:
int32 seq
uint64 time
byte[1048576] input_tensor
---
int32 seq
uint64 time
byte[1048576] output_tensor
- Client side code:
import sys
from my_struct.srv import InferService
import rclpy
from rclpy.node import Node
import time
class MinimalClientAsync(Node):
def __init__(self):
super().__init__('minimal_client_async')
self.cli = self.create_client(InferService, 'infer')
while not self.cli.wait_for_service(timeout_sec=1.0):
self.get_logger().info('service not available, waiting again...')
self.req = InferService.Request()
def send_request(self):
self.req.seq = 2000
self.req.time = 200
self.future = self.cli.call_async(self.req)
def main(args=None):
rclpy.init(args=args)
minimal_client = MinimalClientAsync()
for _ in range(100000):
minimal_client.send_request()
while rclpy.ok():
rclpy.spin_once(minimal_client)
if minimal_client.future.done():
try:
response = minimal_client.future.result()
except Exception as e:
minimal_client.get_logger().info(
'Service call failed %r' % (e,))
else:
minimal_client.get_logger().info(
'Result of inference: resp seq %d' % (response.seq))
break
#time.sleep(0.5)
minimal_client.destroy_node()
rclpy.shutdown()
if __name__ == '__main__':
main()
You can write a simple service code, just receive the request and do nothing and send a response to client.
Issue Analytics
- State:
- Created 2 years ago
- Comments:16 (8 by maintainers)
Top Results From Across the Web
Requests memory leak · Issue #4601 · psf/requests - GitHub
I have tryied with 2 - 200 threads and memory leaks anyway. Im not using a tool, i just did this changes to...
Read more >Memory Leak in Python requests - GeeksforGeeks
When a programmer forgets to clear a memory allocated in heap memory, the memory leak occurs. It's a type of resource leak or...
Read more >Memory leak in c++ python wrapper - Stack Overflow
I have finally found the segfault. The header I was using for compiling the program was different from the one used by the...
Read more >Debugging and preventing memory errors in Python - Medium
This case is essentially the same case outlined in the intro: a server runs out of memory while processing a request. The dangerous...
Read more >Memory leak in sockets - Discussions on Python.org
The client send a random data to forwarder server that forward data to “echo server”, and the echo server send back received data....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
problem confirmed, in the process space there is a lot of heap memory area mapped. as long as client/service running, virtual/physical memory increases. i created the reproducible sample program, https://github.com/fujitatomoya/ros2_test_prover/tree/master/prover_rclpy.
under colcon envirnoment,
CC: @Barry-Xu-2018 @iuhilnehc-ynos could you take a look if you have time? i guess this is memory leak, if i am not mistaken…
You don’t need to do reset() manually, just let the unique_ptr with its
destroy_ros_message_function
do the magic.Refer to https://github.com/ros2/rclpy/blob/691e4fbfcb4bd4cc2a01182a7dced3105a78200b/rclpy/src/rclpy/action_client.cpp#L102-L121