From d55503bb3456e006c2e0ffb7299fe2c65aad1a2e Mon Sep 17 00:00:00 2001 From: Christina Date: Thu, 4 Dec 2025 15:14:38 -0600 Subject: [PATCH] fix: Support pool_maxsize parameter for concurrent connections UnixHTTPConnectionPool was not passing maxsize to the parent HTTPConnectionPool, causing it to always use the default of 1. This resulted in "Connection pool is full, discarding connection" warnings when making concurrent requests through a Unix socket. Changes: - UnixHTTPConnectionPool now accepts maxsize parameter and passes it to parent class - UnixAdapter now accepts pool_maxsize parameter (default 1 for backwards compatibility) and passes it to UnixHTTPConnectionPool This allows users to configure larger connection pools for concurrent request scenarios: adapter = UnixAdapter(pool_maxsize=10) session.mount('http+unix://', adapter) --- requests_unixsocket/adapters.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/requests_unixsocket/adapters.py b/requests_unixsocket/adapters.py index d40a19f..d86008a 100644 --- a/requests_unixsocket/adapters.py +++ b/requests_unixsocket/adapters.py @@ -39,9 +39,9 @@ def connect(self): class UnixHTTPConnectionPool(urllib3.connectionpool.HTTPConnectionPool): - def __init__(self, socket_path, timeout=60): + def __init__(self, socket_path, timeout=60, maxsize=1, **kwargs): super(UnixHTTPConnectionPool, self).__init__( - 'localhost', timeout=timeout) + 'localhost', timeout=timeout, maxsize=maxsize, **kwargs) self.socket_path = socket_path self.timeout = timeout @@ -51,9 +51,11 @@ def _new_conn(self): class UnixAdapter(HTTPAdapter): - def __init__(self, timeout=60, pool_connections=25, *args, **kwargs): + def __init__(self, timeout=60, pool_connections=25, pool_maxsize=1, + *args, **kwargs): super(UnixAdapter, self).__init__(*args, **kwargs) self.timeout = timeout + self.pool_maxsize = pool_maxsize self.pools = urllib3._collections.RecentlyUsedContainer( pool_connections, dispose_func=lambda p: p.close() ) @@ -75,7 +77,7 @@ def get_connection(self, url, proxies=None): if pool: return pool - pool = UnixHTTPConnectionPool(url, self.timeout) + pool = UnixHTTPConnectionPool(url, self.timeout, maxsize=self.pool_maxsize) self.pools[url] = pool return pool