Skip to content

Commit 8cfb4ca

Browse files
ios: retry curl with http1.1, attempt to fix curl failure
1 parent 19824ff commit 8cfb4ca

File tree

1 file changed

+30
-10
lines changed

1 file changed

+30
-10
lines changed

Apple/__main__.py

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -345,16 +345,36 @@ def download(url: str, target_dir: Path) -> Path:
345345

346346
out_path = target_path / basename(url)
347347
if not Path(out_path).is_file():
348-
run([
349-
"curl",
350-
"-Lf",
351-
"--retry",
352-
"5",
353-
"--retry-all-errors",
354-
"-o",
355-
out_path,
356-
url,
357-
])
348+
curl_attempts = [
349+
[],
350+
# Retry over HTTP/1.1 if the initial transfer fails with a curl
351+
# transport error (commonly seen with some runner/proxy setups).
352+
["--http1.1"],
353+
]
354+
for i, extra_args in enumerate(curl_attempts, 1):
355+
try:
356+
run([
357+
"curl",
358+
"-Lf",
359+
"--retry",
360+
"5",
361+
"--retry-all-errors",
362+
*extra_args,
363+
"-o",
364+
out_path,
365+
url,
366+
])
367+
except CalledProcessError as exc:
368+
if i < len(curl_attempts) and exc.returncode in {16, 56, 92}:
369+
out_path.unlink(missing_ok=True)
370+
print(
371+
f"curl exited {exc.returncode}; "
372+
"retrying download with --http1.1"
373+
)
374+
continue
375+
raise
376+
else:
377+
break
358378
else:
359379
print(f"Using cached version of {basename(url)}")
360380
return out_path

0 commit comments

Comments
 (0)