Drain stdio responses after redirected stdin EOF#2682
Conversation
4dd758d to
f1c0e22
Compare
There was a problem hiding this comment.
I checked this against the stdio EOF case from #2678.
The focused tests pass locally:
TMPDIR=.codex-tmp/tmp UV_CACHE_DIR=.codex-tmp/uv-cache uv run --frozen pytest tests/issues/test_2678_stdio_eof_drain.py tests/server/test_cancel_handling.py tests/server/test_session.py -q
I also ran a local memory-stream probe for the shutdown edge where an accepted tools/call handler never finishes after stdin/read EOF. With drain_in_flight_on_read_eof=True and drain_in_flight_on_read_eof_timeout_seconds=0.2, server.run() returned after the bounded drain window instead of hanging indefinitely.
That covers the main lifecycle risk I was looking for: redirected stdin gets a chance to flush accepted responses, but EOF is still a bounded shutdown signal. I did not find an issue in this pass.
Fixes #2678.
Summary
Tests
python -m ruff check src/mcp/shared/session.py src/mcp/server/session.py src/mcp/server/lowlevel/server.py src/mcp/server/mcpserver/server.py tests/issues/test_2678_stdio_eof_drain.pypython -m ruff format --check src/mcp/shared/session.py src/mcp/server/session.py src/mcp/server/lowlevel/server.py src/mcp/server/mcpserver/server.py tests/issues/test_2678_stdio_eof_drain.pypython -m pyright src/mcp/shared/session.py src/mcp/server/session.py src/mcp/server/lowlevel/server.py src/mcp/server/mcpserver/server.py tests/issues/test_2678_stdio_eof_drain.pypython -m pytest tests/issues/test_2678_stdio_eof_drain.py tests/server/test_cancel_handling.py tests/server/test_session.py -q