From c92c93e6d56975c47bd8b2e0dea3a8cfba81960b Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Wed, 10 May 2023 16:31:53 -0400 Subject: [PATCH] Clean up cached HTTP connections on shutdown. --- newsfragments/4028.minor | 0 src/allmydata/storage/http_client.py | 7 ++++++- src/allmydata/storage_client.py | 5 +++++ 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 newsfragments/4028.minor diff --git a/newsfragments/4028.minor b/newsfragments/4028.minor new file mode 100644 index 000000000..e69de29bb diff --git a/src/allmydata/storage/http_client.py b/src/allmydata/storage/http_client.py index 0e12df7ce..e2b45e30c 100644 --- a/src/allmydata/storage/http_client.py +++ b/src/allmydata/storage/http_client.py @@ -310,6 +310,7 @@ class StorageClient(object): _base_url: DecodedURL _swissnum: bytes _treq: Union[treq, StubTreq, HTTPClient] + _pool: HTTPConnectionPool _clock: IReactorTime @classmethod @@ -339,7 +340,7 @@ class StorageClient(object): ) 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: """Get a URL relative to the base URL.""" @@ -479,6 +480,10 @@ class StorageClient(object): ).read() raise ClientException(response.code, response.phrase, data) + def shutdown(self) -> Deferred: + """Shutdown any connections.""" + return self._pool.closeCachedConnections() + @define(hash=True) class StorageClientGeneral(object): diff --git a/src/allmydata/storage_client.py b/src/allmydata/storage_client.py index a40e98b03..94aae43f6 100644 --- a/src/allmydata/storage_client.py +++ b/src/allmydata/storage_client.py @@ -1271,6 +1271,11 @@ class HTTPNativeStorageServer(service.MultiService): if self._lc.running: self._lc.stop() 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