/admin/* answered on the 0.0.0.0 listener with no auth and no method check: GET /admin/pause/<endpoint>, GET /admin/flush/cache, and /spend and /metrics were reachable from the LAN (measured 200 from 172.25.206.16). A plain GET means any page the operator visits can fire it with an <img>. They are now loopback-only (403 otherwise); /status stays open because clients poll it, and /metrics keeps its own listener. An endpoint that declares api_key_env but has no key set forwarded the client's Authorization header upstream: a stub received "Bearer SUPER-SECRET-TOKEN". The rotation now tries every key of the endpoint and fails with no_key when none is set, instead of passing the caller's junction key to a provider. j_conn_write blocked in write() with no deadline; a peer that stopped reading pinned its connection thread and its inflight slot forever, so 32 of them stalled the router. Accepted sockets get SO_SNDTIMEO 15 s, EAGAIN/WANT_WRITE ends the request after a bounded stall, and relay_stream never writes past a declared Content-Length. X-Forwarded-For now carries the real peer address instead of a literal 127.0.0.1. Tests: the stub can send SSE chunked (--sse), with "Transfer-Encoding: Chunked" (--sse-cap) and with framing but no header (--sse-no-te); run.sh checks that no framing reaches the client, that the management endpoints refuse a LAN peer and still answer on loopback, and that a key-less endpoint fails without forwarding the caller's header. Full suite: 537 OK, 0 FAIL, PASS. The tree also carried the in-flight endpoint/tool-error work (models.c glob match, base_cmd resolution, body_is_request_error, probe/README); committed with it so the tree is clean.
140 lines
5.0 KiB
Bash
Executable File
140 lines
5.0 KiB
Bash
Executable File
#!/bin/bash
|
|
# Wird von tests/run.sh eingebunden: Erreichbarkeit im Hintergrund prüfen.
|
|
#
|
|
# Der Fall: eine Box ist weg. Der Router soll das merken, bevor die erste Anfrage
|
|
# daran hängen bleibt — sie für eine Weile offline nehmen und danach von selbst wieder
|
|
# nachsehen, statt bei jeder Anfrage erneut in den Zeitablauf zu laufen.
|
|
|
|
echo
|
|
echo "== 38. Erreichbarkeit im Hintergrund (offline, dann wieder prüfen) =="
|
|
|
|
PP=$((PORT+222))
|
|
P_ALIVE=$((PORT+223))
|
|
P_DEAD=$((PORT+224))
|
|
|
|
tests/stub $P_ALIVE "ALIVE" > "$TMP/probe_stub.log" 2>&1 &
|
|
PIDS+=($!)
|
|
sleep 0.4
|
|
|
|
cat > "$TMP/probe.conf" <<CFG
|
|
listen 127.0.0.1:$PP
|
|
log_prefix pr
|
|
probe_interval 2
|
|
probe_timeout 1
|
|
offline_hold_s 4
|
|
queue_timeout 10
|
|
endpoint alive { base http://127.0.0.1:$P_ALIVE/v1; timeout 10 }
|
|
endpoint dead { base http://127.0.0.1:$P_DEAD/v1; timeout 10 }
|
|
req for "*" check none pass dead, alive
|
|
CFG
|
|
./junction --config "$TMP/probe.conf" > "$TMP/probe.log" 2>&1 &
|
|
PIDS+=($!)
|
|
wait_port "$PP" 10 || bad "the probe instance did not come up"
|
|
|
|
# Zwei Intervalle abwarten: der tote Endpunkt muss ohne jede Anfrage auffallen.
|
|
log_has "$TMP/probe.log" "probe_offline endpoint=dead" \
|
|
"a dead endpoint is noticed without a request being sent to it"
|
|
|
|
dead_off=$(curl -s -m 5 "http://127.0.0.1:$PP/status" | python3 -c "
|
|
import sys,json
|
|
d=json.load(sys.stdin)
|
|
for e in d['endpoints']:
|
|
if e['name']=='dead': print(e['offline_s'], e['probe_ok'])")
|
|
set -- $dead_off
|
|
if [ "${1:-0}" -gt 0 ] && [ "${2:-1}" = "0" ]; then
|
|
ok "it is offline for a while (${1}s left) and marked as not answering"
|
|
else
|
|
bad "/status does not show it offline (offline_s=$1 probe_ok=$2)"
|
|
fi
|
|
|
|
# Die Anfrage geht am toten Ziel vorbei, ohne dessen Zeitablauf zu bezahlen.
|
|
read -r pcode ptime < <(curl -s -o /dev/null -m 15 -w '%{http_code} %{time_total}' \
|
|
-X POST -H 'Content-Type: application/json' \
|
|
-d '{"model":"m","messages":[{"role":"user","content":"x"}],"max_tokens":3}' \
|
|
"http://127.0.0.1:$PP/v1/chat/completions")
|
|
if [ "$pcode" = "200" ] && awk "BEGIN{exit !($ptime < 2.0)}"; then
|
|
ok "the request skips the offline target without waiting for it (${ptime}s)"
|
|
else
|
|
bad "the request still paid for the dead target: http=$pcode after ${ptime}s"
|
|
fi
|
|
|
|
# Jetzt kommt die Box zurück: die Prüfung muss sie von selbst wieder aufnehmen.
|
|
tests/stub $P_DEAD "REVIVED" > "$TMP/probe_revived.log" 2>&1 &
|
|
PIDS+=($!)
|
|
log_has "$TMP/probe.log" "probe_recovered endpoint=dead" \
|
|
"the returning endpoint is picked up by the next check, not by a failure"
|
|
|
|
revived=$(curl -s -m 5 "http://127.0.0.1:$PP/status" | python3 -c "
|
|
import sys,json
|
|
d=json.load(sys.stdin)
|
|
for e in d['endpoints']:
|
|
if e['name']=='dead': print(e['probe_ok'], int(e['offline_s']))")
|
|
set -- $revived
|
|
if [ "${1:-0}" = "1" ] && [ "${2:-1}" = "0" ]; then
|
|
ok "it is back: probe_ok=1, no offline hold left"
|
|
else
|
|
bad "the endpoint did not come back (probe_ok=$1 offline_s=$2)"
|
|
fi
|
|
|
|
# Und die Prüfung ist abschaltbar (probe off) — nicht jedes Ziel darf gefragt werden.
|
|
cat > "$TMP/probe_off.conf" <<CFG
|
|
listen 127.0.0.1:$((PORT+225))
|
|
log_prefix po
|
|
probe_interval 1
|
|
endpoint quiet { base http://127.0.0.1:$P_DEAD/v1; probe off; timeout 5 }
|
|
req for "*" check none pass quiet
|
|
CFG
|
|
./junction --config "$TMP/probe_off.conf" > "$TMP/probe_off.log" 2>&1 &
|
|
PIDS+=($!)
|
|
wait_port "$((PORT+225))" 10 || bad "the probe-off instance did not come up"
|
|
sleep 2.5
|
|
if grep -q "probe_offline endpoint=quiet" "$TMP/probe_off.log" 2>/dev/null; then
|
|
bad "a probe off endpoint was checked anyway"
|
|
else
|
|
ok "probe off keeps an endpoint out of the check"
|
|
fi
|
|
|
|
# base_cmd ist die Adresse, nicht base. opencode serve bindet bei jedem Start einen
|
|
# neuen Port; eine Prüfung gegen die alte Adresse nimmt den gesunden Dienst offline
|
|
# und jede Anfrage bekommt 503, obwohl er läuft.
|
|
echo
|
|
echo "== 39. Hintergrundprüfung folgt base_cmd =="
|
|
PP2=$((PORT+300))
|
|
P_DYN=$((PORT+301))
|
|
P_STALE=$((PORT+302))
|
|
tests/stub $P_DYN "DYNAMIC" > "$TMP/probe_dynamic_stub.log" 2>&1 &
|
|
PIDS+=($!)
|
|
sleep 0.4
|
|
cat > "$TMP/probe_base_cmd.conf" <<CFG
|
|
listen 127.0.0.1:$PP2
|
|
log_prefix pb
|
|
probe_interval 1
|
|
probe_timeout 1
|
|
offline_hold_s 30
|
|
endpoint dynamic {
|
|
base http://127.0.0.1:$P_STALE/v1
|
|
base_cmd "echo http://127.0.0.1:$P_DYN/v1"
|
|
timeout 10
|
|
}
|
|
req for "*" check none pass dynamic
|
|
CFG
|
|
./junction --config "$TMP/probe_base_cmd.conf" > "$TMP/probe_base_cmd.log" 2>&1 &
|
|
PIDS+=($!)
|
|
wait_port "$PP2" 10 || bad "the base_cmd probe instance did not come up"
|
|
sleep 2.5
|
|
dyn_state=$(curl -s -m 5 "http://127.0.0.1:$PP2/status" | python3 -c "
|
|
import sys,json
|
|
d=json.load(sys.stdin)
|
|
for e in d['endpoints']:
|
|
if e['name']=='dynamic': print(e['probe_ok'], int(e['offline_s']))")
|
|
set -- $dyn_state
|
|
if [ "${1:-0}" = "1" ] && [ "${2:-1}" = "0" ]; then
|
|
ok "the probe checks the address reported by base_cmd"
|
|
else
|
|
bad "the probe used the stale base address (probe_ok=$1 offline_s=$2)"
|
|
fi
|
|
R=$(curl -s -m 15 -X POST -H 'Content-Type: application/json' \
|
|
-d '{"model":"m","messages":[{"role":"user","content":"x"}],"max_tokens":3}' \
|
|
"http://127.0.0.1:$PP2/v1/chat/completions")
|
|
contains "$R" "served by DYNAMIC" "a base_cmd endpoint is not skipped as offline"
|