Repository navigation
Commit f2626f0
committed
fix(mcp): exit promptly on stdin EOF over a FIFO (macOS poll deficiency)
The stdio server's input loop blocked in one poll() for the full idle timeout
(STORE_IDLE_TIMEOUT_S = 60s). On macOS, poll() and select() do NOT report
POLLIN/POLLHUP when a FIFO's last writer closes — only read() returns 0 there
(verified with a standalone probe). So when a client closed the server's stdin
over a named FIFO, the server did not observe the EOF until the 60s poll timed
out and the loop's Phase-2 read() then returned 0 — i.e. it appeared to hang for
up to a minute after the client went away.
Bound the blocking poll to MCP_TIMEOUT_MS (~1s) instead of the full idle timeout
so the existing read()-based EOF check runs within ~1s. Idle-store eviction
(threshold STORE_IDLE_TIMEOUT_S) is idempotent, so checking it on each short tick
is harmless. Real MCP clients connect stdin via a pipe, which macOS poll() does
handle, so they were unaffected; FIFO-based transports (and the smoke
clean-eof-exit invariant) hung.
Reproduce-first: scripts/smoke-invariants.sh clean-eof-exit was RED (>12s EOF
hang) and is now GREEN (exit 0 within bound); the full battery is 30/0.
Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>1 parent 2a4fac6 commit f2626f0
1 file changed
Lines changed: 12 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5563 | 5563 | | |
5564 | 5564 | | |
5565 | 5565 | | |
5566 | | - | |
5567 | | - | |
| 5566 | + | |
| 5567 | + | |
| 5568 | + | |
5568 | 5569 | | |
5569 | 5570 | | |
5570 | 5571 | | |
| |||
5584 | 5585 | | |
5585 | 5586 | | |
5586 | 5587 | | |
5587 | | - | |
5588 | | - | |
| 5588 | + | |
| 5589 | + | |
| 5590 | + | |
| 5591 | + | |
| 5592 | + | |
| 5593 | + | |
| 5594 | + | |
| 5595 | + | |
| 5596 | + | |
5589 | 5597 | | |
5590 | 5598 | | |
5591 | 5599 | | |
| |||
0 commit comments