Skip to content
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 in rosgraph for kernel < 4.16 and Python 3 #1

Closed
wants to merge 1 commit into from

Conversation

schadocalex
Copy link
Owner

Following ros#2132 and the discussion from ros#2132 (comment), here is a fix for the memory leak detected in Python 3 with kernel < 4.16.

I see no reason why daemon_threads should depend on the HTTP version. The only reason the changes were grouped together was to "switch off" the change in https://github.com/ros/ros_comm/pull/1287/files, which we observed introduced the problem.

I have tested it with kernel 4.15 (with the bug) and 4.18 (without the bug), works for both in Python3.

The memory leak is due to the ThreadingMixin referencing all threads, with daemon_threads = False and block_on_close = True by default:
https://github.com/python/cpython/blob/3.8/Lib/socketserver.py#L696
It only releases the memory when the server is closed. That's not a real memory leak as the memory is released at the end but roscore is designed to run for a long time. In my project it represents 3Go/hour of unreleased RAM in rosmaster.

Even the native ThreadingHTTPServer has the option enabled by default: https://github.com/python/cpython/blob/3.8/Lib/http/server.py#L144

For Python2 the problem does not exist, since there is no block_on_close option.
https://github.com/python/cpython/blob/v2.7.15/Lib/SocketServer.py#L582

@schadocalex
Copy link
Owner Author

Not the right repo to PR :p

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant