Mirror probe: guard failures under set -e, reject HTTP errors

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QKxGW1raAWaqeU8WdHsMsp
This commit is contained in:
2026-08-24 18:40:27 -04:00
co-authored by Claude Fable 5
parent 434f848dd8
commit aabe95b887
+18 -14
View File
@@ -24,23 +24,27 @@ cn_mirror_ids_by_region() {
# Probe one mirror: prints "<speed_bytes_s> <ttfb_s> <sync_age_s|stale|unknown>"
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