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

Memory leak because session is not closed #195

Closed
lonvia opened this issue Mar 20, 2022 · 3 comments
Closed

Memory leak because session is not closed #195

lonvia opened this issue Mar 20, 2022 · 3 comments

Comments

@lonvia
Copy link
Member

lonvia commented Mar 20, 2022

The ReplicationServer opens a requests session which is never closed. The result is a memory leak.

See osm-search/Nominatim#2575 for a practical case where this is an issue.

I'm not sure if this can be resolved transparently. We may have to introduce a close() function for ReplicationServer to fix the issue.

Addendum: this is not a new bug that came in with the requests implementation. The urllib code had the same behaviour.

@wiktorn
Copy link
Contributor

wiktorn commented Mar 20, 2022

Worth checking this bug: psf/requests#4601

The only way this can be done transparently, is to do it in del method of ReplicationServer, though it's kind of band-aid.

@lonvia
Copy link
Member Author

lonvia commented Mar 21, 2022

Barking up the wrong tree, it turns out. It's the MergeInputReader that doesn't properly release the downloaded buffers.

We still should be closing the sessions and requests properly.

lonvia added a commit to lonvia/pyosmium that referenced this issue Mar 21, 2022
PyObject_GetBuffer needs a PyObject_Release which was missing.
Use pybind11's buffer_info as a resource controller. We can't
use the request() function from py::buffer because it uses a
different set of flags.

See osmcode#195.
@lonvia
Copy link
Member Author

lonvia commented Mar 21, 2022

Memory leak fixed in b8b4b72. Proper closing of sessions in bd4daeb. Sessions will now only held open, when ReplicationServer is used in context manager mode (i.e. with a with construct). Otherwise a new session is created for each request. pyosmium-get-changes and pyosmium-up-to-date are adapted to the new use.

@lonvia lonvia closed this as completed Mar 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants