1111import google .auth .transport .requests
1212import google .oauth2 .id_token
1313import requests
14+ from aiohttp import ClientPayloadError
1415from aiohttp import ClientResponse
1516from aiohttp import ClientSession
1617from aiohttp import ClientTimeout
18+ from aiohttp import ServerDisconnectedError
1719from aiohttp import TCPConnector
1820from aiohttp_retry import ExponentialRetry
1921from aiohttp_retry import RetryClient
@@ -129,7 +131,7 @@ async def _post(
129131
130132 split_pseudo_requests = self ._split_requests (pseudo_requests )
131133 aio_session = ClientSession (
132- connector = TCPConnector (limit = 200 , force_close = True ),
134+ connector = TCPConnector (limit = 100 , enable_cleanup_closed = True ),
133135 timeout = ClientTimeout (total = TIMEOUT_DEFAULT ),
134136 )
135137 async with RetryClient (
@@ -139,11 +141,15 @@ async def _post(
139141 start_timeout = 0.1 ,
140142 max_timeout = 30 ,
141143 factor = 6 ,
142- statuses = {
143- 400 ,
144- }.union (
144+ statuses = {400 , 429 }.union (
145145 set (range (500 , 600 ))
146146 ), # Retry all 5xx errors and 400 Bad Request
147+ exceptions = {
148+ ClientPayloadError ,
149+ ServerDisconnectedError ,
150+ asyncio .TimeoutError ,
151+ OSError ,
152+ },
147153 ),
148154 ) as client :
149155 results = await asyncio .gather (
@@ -159,7 +165,7 @@ async def _post(
159165 for req in reqs
160166 ]
161167 )
162- await asyncio .sleep (0.1 ) # Allow time for sockets to close
168+ await asyncio .sleep (0.5 ) # Allow time for sockets to close
163169 await aio_session .close ()
164170
165171 return PseudoClient ._merge_responses (results )
0 commit comments