Skip to content

Commit bf8a1c8

Browse files
cliffhallclaude
andcommitted
fix: bound the HTTP smoke's readiness wait and clean up with a trap
Copilot round 8 on #4921. The recipe runs in a subshell whose EXIT trap stops the server by pid, waits at most ten seconds, and ends the run when the server exits before it listens. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Signed-off-by: cliffhall <[email protected]>
1 parent 77e7d03 commit bf8a1c8

1 file changed

Lines changed: 20 additions & 13 deletions

File tree

‎.claude/skills/client-smoke/SKILL.md‎

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -129,21 +129,28 @@ the URL. The transport is inferred from the path: `/mcp` is Streamable HTTP,
129129
`/sse` is HTTP+SSE.
130130

131131
```sh
132-
PORT=3917 node src/everything/dist/index.js streamableHttp &
133-
SERVER_PID=$!
134-
# Wait for the listener: the server answers before the CLI is pointed at it.
135-
until curl -s -o /dev/null http://localhost:3917/mcp; do sleep 0.2; done
136-
$INSPECT http://localhost:3917/mcp \
137-
--method tools/call --tool-name echo --tool-arg message=over-http --format json
138-
kill "$SERVER_PID" # this server, by pid; `kill %1` would hit whatever job 1 is
132+
(
133+
PORT=3917 node src/everything/dist/index.js streamableHttp >/dev/null 2>&1 &
134+
SERVER_PID=$!
135+
trap 'kill "$SERVER_PID" 2>/dev/null' EXIT # stops it however the subshell ends
136+
for _ in $(seq 50); do # at most ten seconds
137+
curl -s -o /dev/null http://localhost:3917/mcp && break
138+
kill -0 "$SERVER_PID" 2>/dev/null || { echo "server exited before listening" >&2; exit 1; }
139+
sleep 0.2
140+
done
141+
$INSPECT http://localhost:3917/mcp \
142+
--method tools/call --tool-name echo --tool-arg message=over-http --format json
143+
)
139144
```
140145

141-
Stop the server even when the CLI call fails; a listener left on the port
142-
makes the next run talk to the old build.
143-
144-
Without the wait, the CLI can reach the port before the server is listening
145-
and fail with a refused connection. In a separate terminal the equivalent is
146-
waiting for the `listening on port` line on stderr.
146+
Each part of that is there for a failure it prevents. Without the wait, the CLI
147+
can reach the port before the server is listening and exit 4. The wait is
148+
bounded and checks that the server is still alive, so a server that fails to
149+
bind (the port is taken, the build is missing) ends the run instead of hanging
150+
it. The subshell's `EXIT` trap stops the server by pid even when the CLI call
151+
fails; a listener left on the port makes the next run talk to the old build.
152+
By hand in two terminals, the equivalent is waiting for the `listening on
153+
port` line and stopping the server with Ctrl-C.
147154

148155
A change to a tool, resource or prompt of `everything` is checked over stdio
149156
and Streamable HTTP. Check HTTP+SSE as well when the change touches transport

0 commit comments

Comments
 (0)