diff --git a/.gitea/CI_PERFORMANCE.md b/.gitea/CI_PERFORMANCE.md index 2a11e6c..6ce0e28 100644 --- a/.gitea/CI_PERFORMANCE.md +++ b/.gitea/CI_PERFORMANCE.md @@ -56,6 +56,8 @@ the build job must still be rerun; it has no saved app to restore. Release attachment uploads retry temporary network errors, HTTP 408/429 and 500/502/503/504 up to three POST attempts per file, also with 5/15-second delays. +The specific FRP HTML "Not Found" page observed during tunnel reconnection is +also treated as temporary; ordinary Gitea API or HTML 404 responses still fail. Before retrying a POST, the uploader checks whether Gitea already saved the named attachment, including after the final response is lost. This avoids duplicate uploads after a timeout. Authorization, invalid-input and other permanent errors diff --git a/tool/gitea/release_transport.py b/tool/gitea/release_transport.py index fbe1d7c..5bc819a 100644 --- a/tool/gitea/release_transport.py +++ b/tool/gitea/release_transport.py @@ -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)) diff --git a/tool/gitea/test_transfer_tools.py b/tool/gitea/test_transfer_tools.py index a96719c..39798bd 100644 --- a/tool/gitea/test_transfer_tools.py +++ b/tool/gitea/test_transfer_tools.py @@ -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'

Not Found

frp' + 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'

Not Found

'), + ('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 = []