@@ -24,19 +24,17 @@ async def _get_session() -> aiohttp.ClientSession:
2424 async with _session_lock :
2525 # Check again after acquiring lock
2626 if _client_session is None or _client_session .closed :
27- # Configure timeout and connection pooling
27+ # Configure timeout optimized for localhost IPC
2828 timeout = aiohttp .ClientTimeout (
29- total = 60 , # Total timeout for entire request
30- connect = 30 , # Timeout for connection establishment
31- sock_connect = 30 , # Socket connection timeout
32- sock_read = 30 # Socket read timeout
29+ total = 240 , # 4-minute total timeout for slow operations
30+ sock_connect = 10 , # Fast connection over localhost
31+ sock_read = None # Covered by total timeout
3332 )
3433
35- # Configure TCP connector with connection pooling
34+ # Configure TCP connector optimized for localhost IPC
3635 connector = aiohttp .TCPConnector (
37- limit = 100 , # Maximum number of connections
36+ limit = 30 , # Maximum connections for single host
3837 limit_per_host = 30 , # Maximum connections per host
39- ttl_dns_cache = 300 , # DNS cache TTL in seconds
4038 enable_cleanup_closed = True # Enable cleanup of closed connections
4139 )
4240
@@ -54,9 +52,10 @@ async def _handle_request_error():
5452 This handles cases where the remote host process recycles.
5553 """
5654 global _client_session
57- if _client_session is not None and not _client_session .closed :
58- await _client_session .close ()
59- _client_session = None
55+ async with _session_lock :
56+ if _client_session is not None and not _client_session .closed :
57+ await _client_session .close ()
58+ _client_session = None
6059
6160
6261async def _close_session () -> None :
@@ -66,9 +65,10 @@ async def _close_session() -> None:
6665 """
6766 global _client_session
6867
69- if _client_session is not None and not _client_session .closed :
70- await _client_session .close ()
71- _client_session = None
68+ async with _session_lock :
69+ if _client_session is not None and not _client_session .closed :
70+ await _client_session .close ()
71+ _client_session = None
7272
7373
7474async def post_async_request (url : str ,
0 commit comments