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

DM-43739: Fix memory leak in HTTPResourcePath #84

Merged
merged 1 commit into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/changes/DM-43739.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
`ResourePath.root_uri()` now strips query parameters and fragments from the URL. This fixes a memory leak where `HttpResourcePath` would create and cache a new HTTP session for each different set of query parameters.
2 changes: 1 addition & 1 deletion python/lsst/resources/_resourcePath.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ def root_uri(self) -> ResourcePath:
uri : `ResourcePath`
Root URI.
"""
return self.replace(path="", forceDirectory=True)
return self.replace(path="", query="", fragment="", params="", forceDirectory=True)

def split(self) -> tuple[ResourcePath, str]:
"""Split URI into head and tail.
Expand Down
23 changes: 23 additions & 0 deletions tests/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,29 @@ class GenericHttpTestCase(GenericTestCase, unittest.TestCase):
scheme = "http"
netloc = "server.example"

def test_root_uri(self):
self.assertEqual(ResourcePath("http://server.com").root_uri(), ResourcePath("http://server.com/"))
self.assertEqual(
ResourcePath("http://user:password@server.com:3000/").root_uri(),
ResourcePath("http://user:password@server.com:3000/"),
)
self.assertEqual(
ResourcePath("http://user:password@server.com:3000/some/path").root_uri(),
ResourcePath("http://user:password@server.com:3000/"),
)
self.assertEqual(
ResourcePath("http://user:password@server.com:3000/some/path#fragment").root_uri(),
ResourcePath("http://user:password@server.com:3000/"),
)
self.assertEqual(
ResourcePath("http://user:password@server.com:3000/some/path?param=value").root_uri(),
ResourcePath("http://user:password@server.com:3000/"),
)
self.assertEqual(
ResourcePath("http://user:password@server.com:3000/some/path;parameters").root_uri(),
ResourcePath("http://user:password@server.com:3000/"),
)


class HttpReadWriteWebdavTestCase(GenericReadWriteTestCase, unittest.TestCase):
"""Test with a real webDAV server, as opposed to mocking responses."""
Expand Down