Open holesond opened 2 weeks ago
Please note that the results will be retained on the action server for a while (the default is 900 seconds).
You can modify this parameter to determine if it's causing the issue.
i think this can be resolved with https://github.com/ros2/rclpy/pull/1171, default value is way too big...
Thank you @Barry-Xu-2018 and @fujitatomoya for the suggestions. Setting result_timeout=1
has fixed the memory leak for me. A ten second long result_timeout
may still be too long for larger request or response payloads such as images.
@holesond you are welcome.
A ten second long result_timeout may still be too long for larger request or response payloads such as images.
https://github.com/ros2/rclpy/pull/1171 changes default timeout, you can configure the timeout as they like.
Bug report
Required Info:
Steps to reproduce issue
NOTE: The zipped fibonacci_package.zip ROS2 package contains all the files required to reproduce the issue.
Action definition
Fibonacci.action
is similar to https://docs.ros.org/en/jazzy/Tutorials/Intermediate/Creating-an-Action.html.I adapted the action client and server from https://docs.ros.org/en/jazzy/Tutorials/Intermediate/Writing-an-Action-Server-Client/Py.html.
Action client
fibonacci_action_client.py
:Action server
fibonacci_action_server.py
:Start the client before the server, each in a separate terminal:
Expected behavior
Constant memory footprint of both server and client. (Below 100 MiB per process.)
Actual behavior
The client memory footprint is constant (below 78 MiB). However, the server memory footprint grows over time at the rate of ca. 1.3 GiB per minute.
The server prints:
Additional information
The memory leak seems to happen in
/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/action/server.py
, note the allocated 1325 MiB reported by tracemalloc.Line 453 of
/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/action/server.py
is:which calls https://github.com/ros2/rclpy/blob/humble/rclpy/src/rclpy/action_server.cpp#L127.