Skip to content

Commit

Permalink
prevent memory leaks in UrlKeyResolver
Browse files Browse the repository at this point in the history
  • Loading branch information
jschlyter committed Nov 20, 2024
1 parent 469d766 commit f360b64
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion dnstapir/key_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class UrlKeyResolver(CacheKeyResolver):
def __init__(self, client_database_base_url: str, key_cache: KeyCache | None = None):
super().__init__(key_cache=key_cache)
self.client_database_base_url = client_database_base_url
self.httpx_client = httpx.Client()
self._httpx_client: httpx.Client | None = None

def get_public_key_pem(self, key_id: str) -> bytes:
with tracer.start_as_current_span("get_public_key_pem_from_url"):
Expand All @@ -87,3 +87,13 @@ def get_public_key_pem(self, key_id: str) -> bytes:
return response.content
except httpx.HTTPError as exc:
raise KeyError(key_id) from exc

@property
def httpx_client(self) -> httpx.Client:
if self._httpx_client is None:
self._httpx_client = httpx.Client()
return self._httpx_client

def __del__(self):
if self._httpx_client is not None:
self._httpx_client.close()

0 comments on commit f360b64

Please sign in to comment.