Skip to content

Commit 40dff3b

Browse files
authored
Bug 1904784 - retry batched taskcluster requests (#529)
POST requests aren't retried by default, because they may not be idempotent. However both find_task_id_batched and status_task_batched are read-only so there's no reason not to retry.
1 parent 91ac1a1 commit 40dff3b

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/taskgraph/util/taskcluster.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,19 @@ def requests_retry_session(
8181
status_forcelist=(500, 502, 503, 504),
8282
concurrency=CONCURRENCY,
8383
session=None,
84+
allowed_methods=None,
8485
):
8586
session = session or requests.Session()
87+
kwargs = {}
88+
if allowed_methods is not None:
89+
kwargs["allowed_methods"] = allowed_methods
8690
retry = Retry(
8791
total=retries,
8892
read=retries,
8993
connect=retries,
9094
backoff_factor=backoff_factor,
9195
status_forcelist=status_forcelist,
96+
**kwargs,
9297
)
9398

9499
# Default HTTPAdapter uses 10 connections. Mount custom adapter to increase
@@ -110,11 +115,17 @@ def get_session():
110115
return requests_retry_session(retries=5)
111116

112117

113-
def _do_request(url, method=None, **kwargs):
118+
@functools.lru_cache(maxsize=None)
119+
def get_retry_post_session():
120+
allowed_methods = set(("POST",)) | Retry.DEFAULT_ALLOWED_METHODS
121+
return requests_retry_session(retries=5, allowed_methods=allowed_methods)
122+
123+
124+
def _do_request(url, method=None, session=None, **kwargs):
114125
if method is None:
115126
method = "post" if kwargs else "get"
116-
117-
session = get_session()
127+
if session is None:
128+
session = get_session()
118129
if method == "get":
119130
kwargs["stream"] = True
120131

@@ -213,6 +224,7 @@ def find_task_id_batched(index_paths, use_proxy=False):
213224
while True:
214225
response = _do_request(
215226
endpoint,
227+
session=get_retry_post_session(),
216228
json={
217229
"indexes": index_paths,
218230
},
@@ -335,6 +347,7 @@ def status_task_batched(task_ids, use_proxy=False):
335347
while True:
336348
response = _do_request(
337349
endpoint,
350+
session=get_retry_post_session(),
338351
json={
339352
"taskIds": task_ids,
340353
},

0 commit comments

Comments
 (0)