Skip to content

internal/jsonrpc2: allow EOF-side responses to drain#1067

Open
ychampion wants to merge 1 commit into
modelcontextprotocol:mainfrom
ychampion:fix-stdio-eof-drain
Open

internal/jsonrpc2: allow EOF-side responses to drain#1067
ychampion wants to merge 1 commit into
modelcontextprotocol:mainfrom
ychampion:fix-stdio-eof-drain

Conversation

@ychampion

Copy link
Copy Markdown

Read-side EOF currently marks the whole connection as shutting down before handlers for already-read calls can write their responses. For stdio servers driven by one-shot pipes, that drops responses even though stdout is still writable.

This treats io.EOF as a read half-close for in-flight responses: EOF no longer cancels already accepted incoming requests, and response writes only reject explicit close, broken writer, or non-EOF read errors.

Fixes #1061

Validation:

  • red-before: go test ./internal/jsonrpc2 -run TestReadEOFAllowsInFlightResponseToDrain -count=1 failed with Wait returned error: server is closing: EOF
  • go test ./internal/jsonrpc2 -run TestReadEOFAllowsInFlightResponseToDrain -count=1
  • go test ./internal/jsonrpc2 -count=1
  • go test ./mcp -run 'Test(Stdio|Server|Client|InMemory)' -count=1\n- go test ./...\n- go vet ./...\n- git diff --check

@ychampion ychampion force-pushed the fix-stdio-eof-drain branch from 7ee61a5 to ad43d63 Compare July 9, 2026 09:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

stdio: responses to already-received requests are dropped when stdin EOF arrives first (one-shot pipes get no output)

1 participant