From cd7bbd1dbf728a447961e33a29dc58a8ef13c093 Mon Sep 17 00:00:00 2001 From: pyr0ball Date: Tue, 3 Mar 2026 18:11:53 -0800 Subject: [PATCH] =?UTF-8?q?fix(avocet):=20start-api=20polls=20port=20inste?= =?UTF-8?q?ad=20of=20sleeping=201s=20=E2=80=94=20avoids=20false-success=20?= =?UTF-8?q?on=20slow=20start?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- manage.sh | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/manage.sh b/manage.sh index 0979636..5bbfcce 100755 --- a/manage.sh +++ b/manage.sh @@ -272,11 +272,20 @@ case "$CMD" in --host 127.0.0.1 --port "$API_PORT" \ >> "$API_LOG" 2>&1 & echo $! > "$API_PID_FILE" - sleep 1 - if kill -0 "$(<"$API_PID_FILE")" 2>/dev/null; then - success "Avocet API started → http://localhost:${API_PORT} (PID $(<"$API_PID_FILE"))" - else - error "API died. Check ${API_LOG}" + # Poll until port is actually bound (up to 10 s), not just process alive + for _i in $(seq 1 20); do + sleep 0.5 + if (echo "" >/dev/tcp/127.0.0.1/"$API_PORT") 2>/dev/null; then + success "Avocet API started → http://localhost:${API_PORT} (PID $(<"$API_PID_FILE"))" + break + fi + if ! kill -0 "$(<"$API_PID_FILE")" 2>/dev/null; then + rm -f "$API_PID_FILE" + error "API died during startup. Check ${API_LOG}" + fi + done + if ! (echo "" >/dev/tcp/127.0.0.1/"$API_PORT") 2>/dev/null; then + error "API did not bind to port ${API_PORT} within 10 s. Check ${API_LOG}" fi ;;