From ea8700df99f85db5df147362ab4fcf7034355932 Mon Sep 17 00:00:00 2001 From: Julian Sommer <115516918+juliansommer@users.noreply.github.com> Date: Thu, 19 Mar 2026 15:02:50 +1000 Subject: [PATCH] fix: increase sleep time --- scripts/stop-dev.sh | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/scripts/stop-dev.sh b/scripts/stop-dev.sh index 26072249e..10ce060c4 100755 --- a/scripts/stop-dev.sh +++ b/scripts/stop-dev.sh @@ -73,31 +73,35 @@ if is_multinode && [ -z "${SPINIFEX_FORCE_LOCAL_STOP:-}" ] && [ -z "${1:-}" ]; t exec $PROJECT_ROOT/bin/spx admin cluster shutdown fi -# Function to stop a service. Uses `spx service stop` (graceful, kills the -# actual Go process) and falls back to the shell-wrapper PID file if the -# binary isn't available. +# Function to stop a service. Sends SIGTERM and waits for the process to exit +# so resources (ports, DB locks) are fully released before returning. stop_service() { local name="$1" local pidpath="$2" echo "🛑 Stopping $name..." - local rc=0 - if [ -x "$PROJECT_ROOT/bin/spx" ]; then - $PROJECT_ROOT/bin/spx service "$name" stop || rc=$? - elif [ -n "$pidpath" ]; then - kill -SIGTERM $(cat "$pidpath/$name.pid" 2>/dev/null) 2>/dev/null || rc=$? + local pid + pid=$(cat "$pidpath/$name.pid" 2>/dev/null) || { echo "⚠️ No PID file for $name"; return 1; } + + kill -SIGTERM "$pid" 2>/dev/null || { rm -f "$pidpath/$name.pid"; echo "✅ $name already stopped"; echo ""; return 0; } + + # Wait for process to fully exit (up to 15s) so ports/locks are released + local checks=0 + while kill -0 "$pid" 2>/dev/null; do sleep 1 - fi - - if [[ $rc -ne 0 ]]; then - echo "⚠️ Failed to stop $name (exit code $rc)" - return 1 - else - echo "✅ $name stopped" - echo "" - fi + checks=$((checks + 1)) + if [ "$checks" -ge 15 ]; then + echo " Force killing $name..." + kill -9 "$pid" 2>/dev/null || true + sleep 1 + break + fi + done + rm -f "$pidpath/$name.pid" + echo "✅ $name stopped" + echo "" } # Stop services in reverse order