Skip to content

Commit 7d2993a

Browse files
yewreekaclaude
andauthored
fix(local-stack): guard_port no longer kills make up on a fresh stack (#1076)
guard_port() assigns pid from `lsof ... | head -1` under set -euo pipefail. lsof exits non-zero when nothing is listening on the port, which is the normal case on the first `make up` of a fresh stack (before the service has started). The non-zero status propagates out of the command substitution and set -e kills the script before the `[[ -z "$pid" ]] && return 0` emptiness guard runs, so the stack never gets past the first guard_port call. Append `|| true` so an empty result degrades to the guard instead of aborting -- the same pattern the key/token lookups below already use. The bug stays hidden once a service is already running, because svc_running short-circuits before the lsof line. Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
1 parent d155551 commit 7d2993a

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

dev/local-stack/stack.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,11 @@ svc_running() {
8888
guard_port() {
8989
local port="$1" name="$2" dir="$3" pid cmd
9090
svc_running "$name" "$dir" && return 0
91-
pid="$(lsof -tnP -iTCP:"$port" -sTCP:LISTEN 2>/dev/null | head -1)"
91+
# lsof exits non-zero when nothing is listening (the common case on a fresh
92+
# stack before the service starts); under set -euo pipefail that would
93+
# propagate out of the command substitution and kill the script before the
94+
# emptiness guard. Same `|| true` pattern the key/token lookups below use.
95+
pid="$(lsof -tnP -iTCP:"$port" -sTCP:LISTEN 2>/dev/null | head -1)" || true
9296
[[ -z "$pid" ]] && return 0
9397
cmd="$(ps -o command= -p "$pid" 2>/dev/null | head -c 140)"
9498
die "port ${port} is held by a foreign process (pid ${pid}: ${cmd}) — it would shadow ${name} and answer health checks with stale state. Kill it (kill ${pid}) and re-run."

0 commit comments

Comments
 (0)