fix(release): retry FRP tunnel reconnection responses
Gitea CI / Check code and tests (pull_request) Successful in 5m11s
Gitea CI / Build Android APK (pull_request) Failing after 4m12s
Gitea CI / Audit and package Windows x64 (pull_request) Canceled after 0s
Gitea CI / Assemble and validate CI artifacts (pull_request) Canceled after 0s
Gitea CI / Gitea CI passed (pull_request) Canceled after 0s
Gitea CI / Build Windows x64 app (pull_request) Canceled after 5m11s
Gitea CI / Check code and tests (pull_request) Successful in 5m11s
Gitea CI / Build Android APK (pull_request) Failing after 4m12s
Gitea CI / Audit and package Windows x64 (pull_request) Canceled after 0s
Gitea CI / Assemble and validate CI artifacts (pull_request) Canceled after 0s
Gitea CI / Gitea CI passed (pull_request) Canceled after 0s
Gitea CI / Build Windows x64 app (pull_request) Canceled after 5m11s
This commit is contained in:
1 parent
2497865d0e
commit
933ace4e51
3 files changed
+34
No files matched your search
@@ -17,6 +17,11 @@ RETRY_DELAYS = (5, 15)
|
||||
|
||||
def transient(error):
|
||||
if isinstance(error, urllib.error.HTTPError):
|
||||
if error.code == 404 and error.headers.get('Content-Type', '').split(';')[0].lower() == 'text/html':
|
||||
body = error.read(64 * 1024).lower()
|
||||
# FRP returns this page while the vhost tunnel is unavailable.
|
||||
# A normal Gitea API 404 remains a permanent error.
|
||||
return b'github.com/fatedier/frp' in body and b'not found' in body
|
||||
return error.code in {408, 429, 500, 502, 503, 504}
|
||||
return isinstance(error, (urllib.error.URLError, TimeoutError, ConnectionError,
|
||||
http.client.IncompleteRead))
|
||||
|
||||
@@ -9,6 +9,33 @@ import release_transport as transfers
|
||||
|
||||
|
||||
class TransferToolsTests(unittest.TestCase):
|
||||
def test_frp_tunnel_not_found_page_is_retried_as_a_temporary_failure(self):
|
||||
calls = 0
|
||||
|
||||
def transport(url, data=None, method=None, content_type=None):
|
||||
nonlocal calls
|
||||
if method is None:
|
||||
return []
|
||||
calls += 1
|
||||
if calls == 1:
|
||||
body = b'<h1>Not Found</h1><a href="https://github.com/fatedier/frp">frp</a>'
|
||||
raise urllib.error.HTTPError(url, 404, 'Not Found',
|
||||
{'Content-Type': 'text/html; charset=utf-8'}, io.BytesIO(body))
|
||||
return {}
|
||||
|
||||
with patch.object(transfers.time, 'sleep') as sleep:
|
||||
transfers.upload_contents('base', 3, {'app.zip': b'app'}, transport=transport)
|
||||
self.assertEqual(calls, 2)
|
||||
sleep.assert_called_once_with(5)
|
||||
|
||||
def test_ordinary_html_not_found_and_json_api_errors_are_not_retried(self):
|
||||
for content_type, body in [('text/html', b'<h1>Not Found</h1>'),
|
||||
('application/json', b'Not Found github.com/fatedier/frp')]:
|
||||
with self.subTest(content_type=content_type):
|
||||
error = urllib.error.HTTPError('url', 404, 'Not Found',
|
||||
{'Content-Type': content_type}, io.BytesIO(body))
|
||||
self.assertFalse(transfers.transient(error))
|
||||
|
||||
def test_transient_upload_failure_retries_without_restarting_other_files(self):
|
||||
calls = []
|
||||
|
||||
|
||||
Reference in new issue
Block a user