diff --git a/CHANGES.rst b/CHANGES.rst index c9e5f0a..5ce14cd 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,6 +1,12 @@ Changes ======= +(TBD) +----- + +* Connections are no longer reused between requests. + This reduces the amount of ``ServerDisconnectedError`` exceptions. + 0.4.2 (2022-10-28) ------------------ * Bump minimum ``aiohttp`` version to 3.8.0, as earlier versions don't support diff --git a/zyte_api/aio/client.py b/zyte_api/aio/client.py index 164402d..52a47ad 100644 --- a/zyte_api/aio/client.py +++ b/zyte_api/aio/client.py @@ -29,7 +29,8 @@ def create_session(connection_pool_size=100, **kwargs) -> aiohttp.ClientSession: """ Create a session with parameters suited for Zyte API """ kwargs.setdefault('timeout', AIO_API_TIMEOUT) if "connector" not in kwargs: - kwargs["connector"] = TCPConnector(limit=connection_pool_size) + kwargs["connector"] = TCPConnector(limit=connection_pool_size, + force_close=True) return aiohttp.ClientSession(**kwargs) @@ -132,9 +133,9 @@ def request_parallel_as_completed(self, ``queries`` is a list of requests to process (dicts). - ``session`` is an optional aiohttp.ClientSession object; - use it to enable HTTP Keep-Alive. Set the session TCPConnector - limit to a value greater than the number of connections. + ``session`` is an optional aiohttp.ClientSession object. + Set the session TCPConnector limit to a value greater than + the number of connections. """ sem = asyncio.Semaphore(self.n_conn)