fix(bootstrap): 元数据下载在 TLS 握手中断时整体重试

This commit is contained in:
Lemon-miaow committed 2026-09-24 22:26:30 +08:00
1 parent 5cadbd40a9
commit c49336ba21
2 files changed
+50 -7

No files matched your search

+23 -7
View File
@@ -1535,12 +1535,32 @@ game_stack_source() {
# follows — a client that can pass the gate must also be able to reach the lobby. # follows — a client that can pass the gate must also be able to reach the lobby.
# MC_VERSION is read off Limbo's CI artifact name (Limbo-<limbo-ver>-<mc-ver>.jar), which # MC_VERSION is read off Limbo's CI artifact name (Limbo-<limbo-ver>-<mc-ver>.jar), which
# is the only place the pairing is published. # is the only place the pairing is published.
# meta_get prints a small metadata document. curl's --retry covers transient HTTP
# statuses and timeouts; a TLS handshake cut mid-way (exit 35, seen against Fill over
# a flaky IPv6 path) is outside its retry set, so the outer loop retries every failure
# twice more. --retry-all-errors would say the same but needs curl 7.71+.
meta_get() {
local url="$1" out attempt
for attempt in 1 2 3; do
if out="$(curl -fsSL --retry 5 --retry-delay 2 \
-A "felis-bootstrap (+https://github.com/FelisMC/Felis)" "$url")"; then
printf '%s' "$out"
return 0
fi
if [ "$attempt" -lt 3 ]; then
warn "fetching ${url} failed (attempt ${attempt}/3); retrying"
sleep 5
fi
done
return 1
}
resolve_game_jars() { resolve_game_jars() {
local ci="https://ci.loohpjames.com/job/Limbo/lastSuccessfulBuild" meta file base rest paper local ci="https://ci.loohpjames.com/job/Limbo/lastSuccessfulBuild" meta file base rest paper
log "resolving the newest LOOHP/Limbo CI build" log "resolving the newest LOOHP/Limbo CI build"
# Fetch first, filter second: `curl | grep | head` dies of SIGPIPE under `set -o pipefail` # Fetch first, filter second: `curl | grep | head` dies of SIGPIPE under `set -o pipefail`
# the moment head closes the pipe early. Same shape everywhere below. # the moment head closes the pipe early. Same shape everywhere below.
meta="$(curl -fsSL --retry 5 --retry-delay 2 "${ci}/api/json")" \ meta="$(meta_get "${ci}/api/json")" \
|| die "could not read the LOOHP/Limbo CI build metadata" || die "could not read the LOOHP/Limbo CI build metadata"
file="$(printf '%s' "$meta" | grep -o 'Limbo-[0-9A-Za-z._-]*\.jar' || true)" file="$(printf '%s' "$meta" | grep -o 'Limbo-[0-9A-Za-z._-]*\.jar' || true)"
file="${file%%$'\n'*}" file="${file%%$'\n'*}"
@@ -1578,9 +1598,7 @@ resolve_game_jars() {
# Fabric or Velocity jar, neither of which Paper can load. # Fabric or Velocity jar, neither of which Paper can load.
luckperms_latest_jar() { luckperms_latest_jar() {
local json url local json url
json="$(curl -fsSL --retry 5 --retry-delay 2 \ json="$(meta_get "https://metadata.luckperms.net/data/all")" || return 1
-A "felis-bootstrap (+https://github.com/FelisMC/Felis)" \
"https://metadata.luckperms.net/data/all")" || return 1
url="$(printf '%s' "$json" \ url="$(printf '%s' "$json" \
| grep -o 'https://download\.luckperms\.net/[0-9]\{1,\}/bukkit/loader/[^"]*\.jar' || true)" | grep -o 'https://download\.luckperms\.net/[0-9]\{1,\}/bukkit/loader/[^"]*\.jar' || true)"
url="${url%%$'\n'*}" url="${url%%$'\n'*}"
@@ -1600,9 +1618,7 @@ luckperms_latest_jar() {
# unchecked. # unchecked.
papermc_latest_jar() { papermc_latest_jar() {
local project="$1" version="$2" json urls url sha local project="$1" version="$2" json urls url sha
json="$(curl -fsSL --retry 5 --retry-delay 2 \ json="$(meta_get "https://fill.papermc.io/v3/projects/${project}/versions/${version}/builds/latest")" || return 1
-A "felis-bootstrap (+https://github.com/FelisMC/Felis)" \
"https://fill.papermc.io/v3/projects/${project}/versions/${version}/builds/latest")" || return 1
urls="$(printf '%s' "$json" | grep -o 'https://fill-data\.papermc\.io/[^"]*\.jar' || true)" urls="$(printf '%s' "$json" | grep -o 'https://fill-data\.papermc\.io/[^"]*\.jar' || true)"
url="${urls%%$'\n'*}" url="${urls%%$'\n'*}"
[ -n "$url" ] || return 1 [ -n "$url" ] || return 1
+27
View File
@@ -72,11 +72,15 @@ fn="$(awk '/^papermc_latest_jar\(\)/,/^}/' "$BS")"
[ "$(printf '%s\n' "$fn" | wc -l)" -lt 30 ] \ [ "$(printf '%s\n' "$fn" | wc -l)" -lt 30 ] \
|| { echo "FAIL: the extracted papermc_latest_jar is not just the function -- did its closing brace move?"; exit 1; } || { echo "FAIL: the extracted papermc_latest_jar is not just the function -- did its closing brace move?"; exit 1; }
mg="$(awk '/^meta_get\(\)/,/^}/' "$BS")"
[ -n "$mg" ] || { echo "FAIL: no meta_get in $BS"; exit 1; }
rsha=0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef rsha=0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef
run_resolver() { # canned-fill-response run_resolver() { # canned-fill-response
CANNED="$1" bash -c ' CANNED="$1" bash -c '
curl() { printf "%s" "$CANNED"; } curl() { printf "%s" "$CANNED"; }
'"$mg"'
'"$fn"' '"$fn"'
if out="$(papermc_latest_jar velocity 3.5.1)"; then if out="$(papermc_latest_jar velocity 3.5.1)"; then
printf "RESOLVED %s\n" "$out" printf "RESOLVED %s\n" "$out"
@@ -93,6 +97,29 @@ expect "the resolver pairs the url with its own digest" \
out="$(run_resolver '{"url":"https://fill-data.papermc.io/mirror/velocity-3.5.1-615.jar"}')" out="$(run_resolver '{"url":"https://fill-data.papermc.io/mirror/velocity-3.5.1-615.jar"}')"
expect "a URL that carries no digest is refused" "REFUSED" "$out" expect "a URL that carries no digest is refused" "REFUSED" "$out"
# A TLS handshake cut mid-way (curl exit 35) is outside curl's own --retry set, so
# meta_get retries it: two failures, then the answer, still resolves.
tries="$(mktemp)"
out="$(TRIES="$tries" bash -c '
# curl runs in a command substitution, so the attempt count lives in a file.
curl() { printf x >> "$TRIES"; [ "$(wc -c < "$TRIES")" -ge 3 ] || return 35; printf "body"; }
sleep() { :; }
warn() { :; }
'"$mg"'
if out="$(meta_get https://fill.papermc.io/x)"; then printf "GOT %s\n" "$out"; else printf "GAVE UP\n"; fi
')"
rm -f "$tries"
expect "meta_get retries a failed handshake" "GOT body" "$out"
out="$(bash -c '
curl() { return 35; }
sleep() { :; }
warn() { :; }
'"$mg"'
if meta_get https://fill.papermc.io/x >/dev/null; then printf "GOT\n"; else printf "GAVE UP\n"; fi
')"
expect "meta_get gives up after three attempts" "GAVE UP" "$out"
# --- the resolved-Velocity digest gate -------------------------------------------------- # --- the resolved-Velocity digest gate --------------------------------------------------
# The download must hash to what the content-addressed URL promised, BEFORE # The download must hash to what the content-addressed URL promised, BEFORE
# atomic_install_file — the same refusal the Via plugins and the fork jar already get. # atomic_install_file — the same refusal the Via plugins and the fork jar already get.