Skip to content

Commit d554307

Browse files
authored
feat(python): Increase timeout on retries (#5857)
1 parent 55be7cd commit d554307

3 files changed

Lines changed: 30 additions & 14 deletions

File tree

clients/algoliasearch-client-python/algoliasearch/http/retry.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def decide(self, host: Host, response: ApiResponse) -> str:
3434

3535
return RetryOutcome.RETRY
3636
elif self._is_success(response):
37+
host.retry_count = 0
3738
return RetryOutcome.SUCCESS
3839

3940
return RetryOutcome.FAIL

clients/algoliasearch-client-python/algoliasearch/http/transporter.py

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from json import loads
33
from typing import List, Optional
44

5-
from aiohttp import ClientSession, TCPConnector
5+
from aiohttp import ClientSession, ClientTimeout, TCPConnector
66
from async_timeout import timeout
77

88
from algoliasearch.http.api_response import ApiResponse
@@ -56,27 +56,37 @@ async def request(
5656
proxy = self.get_proxy(url)
5757

5858
try:
59-
async with timeout(self._timeout / 1000):
59+
connect_timeout = (
60+
request_options.timeouts["connect"] * (host.retry_count + 1)
61+
) / 1000
62+
request_timeout = self._timeout / 1000
63+
total_timeout = connect_timeout + request_timeout
64+
65+
async with timeout(total_timeout):
66+
timeout_config = ClientTimeout(connect=connect_timeout)
67+
6068
resp = await self._session.request(
6169
method=verb,
6270
url=url,
6371
headers=request_options.headers,
6472
data=request_options.data,
6573
proxy=proxy,
74+
timeout=timeout_config,
6675
)
6776

6877
_raw_data = await resp.text()
69-
response = ApiResponse(
70-
verb=verb,
71-
path=path,
72-
url=url,
73-
host=host.url,
74-
status_code=resp.status,
75-
headers=resp.headers, # pyright: ignore # insensitive dict is still a dict
76-
data=_raw_data,
77-
raw_data=_raw_data,
78-
error_message=str(resp.reason),
79-
)
78+
79+
response = ApiResponse(
80+
verb=verb,
81+
path=path,
82+
url=url,
83+
host=host.url,
84+
status_code=resp.status,
85+
headers=resp.headers, # pyright: ignore # insensitive dict is still a dict
86+
data=_raw_data,
87+
raw_data=_raw_data,
88+
error_message=str(resp.reason),
89+
)
8090

8191
except TimeoutError as e:
8292
response = ApiResponse(

clients/algoliasearch-client-python/algoliasearch/http/transporter_sync.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,14 @@ def request(
7474
).prepare()
7575

7676
try:
77+
connect_timeout = (
78+
request_options.timeouts["connect"] * (host.retry_count + 1)
79+
) / 1000
80+
read_timeout = self._timeout / 1000
81+
7782
resp = self._session.send(
7883
req,
79-
timeout=self._timeout / 1000,
84+
timeout=(connect_timeout, read_timeout),
8085
proxies=proxies,
8186
)
8287

0 commit comments

Comments
 (0)