From 96e2bf992d4864baa8f546734554bf51107f2afe Mon Sep 17 00:00:00 2001 From: maxjivi05 Date: Fri, 23 Oct 2026 21:20:50 -0400 Subject: [PATCH] fix: an HTTP 4xx part hands over to the next CDN at once --- .../usr/local/bin/droiddeck-steam-install | 12 +++++-- tools/tests/test_steam_install.py | 36 ++++++++++++++++--- 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-install b/tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-install index 334ac8f051..45bd96c259 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-install +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-install @@ -105,14 +105,20 @@ fetch() { [ "$bad" -lt 3 ] || { echo "droiddeck-steam-install: $part does not match its checksum" >&2; return 1; } fi before=$(size_of "$dest") - exec {fd}< <(curl -fsSL "${limits[@]}" -C - -o "$dest" "$url" && echo 0 || echo $?) - until read -r -t 5 -u "$fd" rc; do + exec {fd}< <(code=$(curl -fsSL "${limits[@]}" -w '%{http_code}' -C - -o "$dest" "$url") && echo "0 $code" || echo "$? $code") + until read -r -t 5 -u "$fd" rc http; do if [ $? -le 128 ]; then rc=1; break; fi progress "$dest" "$part" done exec {fd}<&- if [ "$rc" = 0 ]; then finished=1; continue; fi - [ "$rc" = 33 ] && rm -f "$dest" + case "$rc:${http:-}" in + 22:416 | 33:*) rm -f "$dest" ;; + 22:4??) + echo "droiddeck-steam-install: $part: HTTP $http from ${url%/*}" >&2 + return 1 + ;; + esac if [ "$(size_of "$dest")" -gt "$before" ]; then failures=0; else failures=$((failures + 1)); fi if [ "$failures" -gt "${#delays[@]}" ]; then echo "droiddeck-steam-install: could not download $part (curl exit $rc); what arrived is kept for the next try" >&2 diff --git a/tools/tests/test_steam_install.py b/tools/tests/test_steam_install.py index 54028187ca..6a02bcb0ae 100644 --- a/tools/tests/test_steam_install.py +++ b/tools/tests/test_steam_install.py @@ -37,9 +37,13 @@ with open(os.environ['TEST_REQUESTS'], 'a') as log: log.write(url + '\\n') with open(os.environ['TEST_REQUESTS'] + '.offsets', 'a') as log: log.write(f'{name} {offset}\\n') +def done(status, code='200'): + if '-w' in args: + sys.stdout.write(code) + sys.exit(status) host_fail = os.environ.get('TEST_FAIL_HOST') if host_fail and host_fail in url: - sys.exit(22) + done(22, '000') action = [] plan = os.environ.get('TEST_PLAN') if plan and os.path.exists(plan): @@ -51,14 +55,16 @@ if plan and os.path.exists(plan): open(plan, 'w').write(''.join(l + '\\n' for l in lines)) break if action[:1] == ['fail']: - sys.exit(int(action[1])) + done(int(action[1]), '000') +if action[:1] == ['http']: + done(22, action[1]) if action[:1] == ['norange'] and offset: - sys.exit(33) + done(33) data = open(os.path.join(os.environ['TEST_CDN'], name), 'rb').read() end = int(action[1]) if action[:1] == ['cut'] else len(data) with open(out, 'ab' if offset else 'wb') as target: target.write(data[offset:end]) -sys.exit(28 if end < len(data) else 0) +done(28 if end < len(data) else 0) ''') curl.chmod(0o755) self.plan = self.root / 'plan' @@ -355,6 +361,28 @@ sys.exit(28 if end < len(data) else 0) self.assertEqual(0, result.returncode, result.stderr) self.assertEqual([0, 400000, 0], self.offsets(client)) + def test_a_missing_part_hands_over_to_the_next_cdn_at_once(self): + files = self.two_parts() + client = files['client_linuxarm64_linuxarm64'] + self.plan_for(client, 'http 404') + result = self.install() + self.assertEqual(0, result.returncode, result.stderr) + self.assertEqual(['https://client-update.steamstatic.com/' + client, + 'https://client-update.akamai.steamstatic.com/' + client], + [line for line in self.requests.read_text().splitlines() if line.endswith(client)]) + self.assertIn('HTTP 404 from https://client-update.steamstatic.com', result.stderr) + self.assertNotIn('trying again', result.stdout) + + def test_a_server_error_is_retried_on_the_same_cdn(self): + files = self.two_parts() + client = files['client_linuxarm64_linuxarm64'] + self.plan_for(client, 'http 503') + result = self.install() + self.assertEqual(0, result.returncode, result.stderr) + self.assertEqual(['https://client-update.steamstatic.com/' + client] * 2, + [line for line in self.requests.read_text().splitlines() if line.endswith(client)]) + self.assertIn('interrupted (curl exit 22), trying again in 0 s', result.stdout) + def test_bytes_that_do_not_check_out_are_fetched_again(self): files = self.two_parts() client = files['client_linuxarm64_linuxarm64']