File: 003.no-httpx-retries.patch

package info (click to toggle)
python-briefcase 0.3.25-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,596 kB
  • sloc: python: 62,519; makefile: 60
file content (79 lines) | stat: -rw-r--r-- 2,811 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
Description: httpx_retries is not in Debian

Mostly reverts upstream 08f776cf

Author: Rebecca N. Palmer <rebecca_palmer@zoho.com>
Forwarded: not-needed

--- a/tests/utils.py
+++ b/tests/utils.py
@@ -6,11 +6,9 @@ import plistlib
 import tarfile
 import zipfile
 from email.message import EmailMessage
-from http import HTTPStatus
 from pathlib import Path
 
 import httpx
-from httpx_retries import Retry, RetryTransport
 from rich.markup import escape
 
 from briefcase.console import Console, InputDisabled
@@ -335,46 +333,17 @@ def file_content(path: Path) -> str | by
 
 def assert_url_resolvable(url: str):
     """Tests whether a URL is resolvable with retries; raises for failure."""
-    transport = RetryTransport(
-        # this retry for the underlying transport only applies to connection attempts
-        transport=httpx.HTTPTransport(retries=3),
-        # the underlying retry timing algorithm (first retry is immediate):
-        #  > backoff_factor * (2^attempt) * random.uniform(jitter, 1)
-        # Here are some example backoff timings using the defaults below:
-        #   [0.0, 0.694, 1.939, 3.588]
-        #   [0.0, 0.529, 1.589, 2.002]
-        #   [0.0, 0.599, 1.948, 4.184]
-        retry=Retry(
-            total=3,
-            backoff_factor=0.6,
-            backoff_jitter=0.3,
-            allowed_methods=[
-                "HEAD",
-                "GET",
-                "PUT",
-                "DELETE",
-                "OPTIONS",
-                "TRACE",
-            ],
-            status_forcelist=[
-                HTTPStatus.TOO_MANY_REQUESTS,
-                HTTPStatus.BAD_GATEWAY,
-                HTTPStatus.SERVICE_UNAVAILABLE,
-                HTTPStatus.GATEWAY_TIMEOUT,
-            ],
-            retry_on_exceptions=[
-                httpx.TimeoutException,
-                httpx.NetworkError,
-                httpx.RemoteProtocolError,
-                httpx.ReadTimeout,
-            ],
-        ),
+    transport = httpx.HTTPTransport(
+        # Retry for connection issues
+        retries=3,
     )
+    with httpx.Client(transport=transport, follow_redirects=True) as client:
+        bad_response_retries = 3
+        retry_status_codes = {500, 502, 504}
+        while bad_response_retries > 0:
+            response = client.head(url)
+            if response.status_code not in retry_status_codes:
+                # break if the status code is not one we care to retry (hopefully a success!)
+                break
 
-    try:
-        with httpx.Client(transport=transport, follow_redirects=True) as client:
-            response = client.head(url, timeout=10)
         response.raise_for_status()
-    finally:
-        # RetryTransport doesn't close its transport...so close it manually
-        transport._sync_transport.close()