Clean up cached HTTP connections on shutdown.

This commit is contained in:
Itamar Turner-Trauring 2023-05-10 16:31:53 -04:00
parent 94a91b68c0
commit c92c93e6d5
3 changed files with 11 additions and 1 deletions

0
newsfragments/4028.minor Normal file
View File

View File

@ -310,6 +310,7 @@ class StorageClient(object):
_base_url: DecodedURL _base_url: DecodedURL
_swissnum: bytes _swissnum: bytes
_treq: Union[treq, StubTreq, HTTPClient] _treq: Union[treq, StubTreq, HTTPClient]
_pool: HTTPConnectionPool
_clock: IReactorTime _clock: IReactorTime
@classmethod @classmethod
@ -339,7 +340,7 @@ class StorageClient(object):
) )
https_url = DecodedURL().replace(scheme="https", host=nurl.host, port=nurl.port) https_url = DecodedURL().replace(scheme="https", host=nurl.host, port=nurl.port)
return cls(https_url, swissnum, treq_client, reactor) return cls(https_url, swissnum, treq_client, pool, reactor)
def relative_url(self, path: str) -> DecodedURL: def relative_url(self, path: str) -> DecodedURL:
"""Get a URL relative to the base URL.""" """Get a URL relative to the base URL."""
@ -479,6 +480,10 @@ class StorageClient(object):
).read() ).read()
raise ClientException(response.code, response.phrase, data) raise ClientException(response.code, response.phrase, data)
def shutdown(self) -> Deferred:
"""Shutdown any connections."""
return self._pool.closeCachedConnections()
@define(hash=True) @define(hash=True)
class StorageClientGeneral(object): class StorageClientGeneral(object):

View File

@ -1271,6 +1271,11 @@ class HTTPNativeStorageServer(service.MultiService):
if self._lc.running: if self._lc.running:
self._lc.stop() self._lc.stop()
self._failed_to_connect("shut down") self._failed_to_connect("shut down")
maybe_storage_server = self.get_storage_server()
if maybe_storage_server is not None:
result.addCallback(lambda _: maybe_storage_server._http_client.shutdown())
return result return result