From aabe95b887049c0715e47b8dada42cb85903b9ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=B7=E7=94=B5=E8=8A=BD=E8=A1=A3?= Date: Mon, 24 Aug 2026 18:40:27 -0400 Subject: [PATCH] Mirror probe: guard failures under set -e, reject HTTP errors Co-Authored-By: Claude Fable 5 Claude-Session: https://claude.ai/code/session_01QKxGW1raAWaqeU8WdHsMsp --- cn/lib/mirror.sh | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/cn/lib/mirror.sh b/cn/lib/mirror.sh index 3108a2b7..3db2e965 100644 --- a/cn/lib/mirror.sh +++ b/cn/lib/mirror.sh @@ -24,23 +24,27 @@ cn_mirror_ids_by_region() { # Probe one mirror: prints " " cn_mirror_probe() { local url="$1" - local speed ttfb lastsync age now + local out speed=0 ttfb=0 lastsync age="unknown" now - read -r speed ttfb < <(curl -sS -o /dev/null -m 12 --connect-timeout 5 \ - -w '%{speed_download} %{time_starttransfer}\n' \ - "$url/core/os/x86_64/core.db" 2>/dev/null) || true - speed="${speed%%.*}" - [[ -z $speed ]] && speed=0 - - age="unknown" - lastsync=$(curl -sS -m 5 --connect-timeout 5 "$url/lastsync" 2>/dev/null | tr -cd '0-9') - if [[ -n $lastsync ]]; then - now=$(date +%s) - age=$((now - lastsync)) - (( age > 86400 )) && age="stale" + if out=$(curl -sSf -o /dev/null -m 12 --connect-timeout 5 \ + -w '%{speed_download} %{time_starttransfer}' \ + "$url/core/os/x86_64/core.db" 2>/dev/null); then + read -r speed ttfb <<<"$out" + speed="${speed%%.*}" fi - echo "$speed ${ttfb:-0} $age" + if lastsync=$(curl -sSf -m 5 --connect-timeout 5 "$url/lastsync" 2>/dev/null); then + lastsync=$(tr -cd '0-9' <<<"$lastsync") + if [[ -n $lastsync ]]; then + now=$(date +%s) + age=$((now - lastsync)) + if (( age > 86400 )); then + age="stale" + fi + fi + fi + + echo "$speed $ttfb $age" } # Rank ids by probe speed, excluding dead (speed 0) and stale mirrors