From f75851d6cfffff5cd000eb64ac00139f26ea604b Mon Sep 17 00:00:00 2001 From: Inferencebot Date: Thu, 22 Oct 2026 08:25:11 -0600 Subject: [PATCH] start.sh: kill stale tinfoil-proxy before bind + fail hard if the proxy never comes up MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The 3301 'address already in use' on process-level restarts left an unmanaged old proxy serving (pre-update code/flags) while the new one died. Also: if the proxy never binds, exit 1 instead of exec-ing LiteLLM against a dead 3301 — that masqueraded as a provider outage. Cache continuity: with TINFOIL_USER_CACHE_SECRET now pinned (env, 2026-10-22), restarts keep Tinfoil's prompt-cache warm either way. --- start.sh | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/start.sh b/start.sh index cf64ed3..2583ce6 100644 --- a/start.sh +++ b/start.sh @@ -170,11 +170,33 @@ if [ ! -f "$TINFOIL_PROXY_BIN" ]; then fi echo "Starting Tinfoil proxy on 127.0.0.1:3301..." +# Kill any stale proxy from a previous start attempt first — on process-level +# restarts (container NOT recreated) the old proxy still holds 127.0.0.1:3301 +# and the new one dies with "bind: address already in use", leaving an +# unmanaged listener running pre-update code/flags. +pkill -f "tinfoil-proxy" 2>/dev/null || true +sleep 1 "$TINFOIL_PROXY_BIN" -b 127.0.0.1 -p 3301 & TINFOIL_PROXY_PID=$! echo "Tinfoil proxy PID: $TINFOIL_PROXY_PID" -# Give the proxy a moment to verify the enclave attestation -sleep 3 +# Give the proxy a moment to verify the enclave attestation, and FAIL HARD if +# it didn't come up — LiteLLM routing to a dead 3301 breaks every tinfoil +# request, and a silent continue makes that look like a provider outage. +proxy_up=0 +for _ in $(seq 1 10); do + if kill -0 "$TINFOIL_PROXY_PID" 2>/dev/null && \ + (exec 3<>"/dev/tcp/127.0.0.1/3301") 2>/dev/null; then + exec 3>&- 3<&- || true + proxy_up=1 + break + fi + sleep 1 +done +if [ "$proxy_up" != "1" ]; then + echo "FATAL: tinfoil-proxy did not bind 127.0.0.1:3301" >&2 + exit 1 +fi +echo "Tinfoil proxy is up on 127.0.0.1:3301" exec litellm --config "$CONFIG_FILE" --port 4000 --host 0.0.0.0 \ No newline at end of file