internal/jsonrpc2: allow EOF-side responses to drain#1067
Open
ychampion wants to merge 1 commit into
Open
Conversation
ychampion
force-pushed
the
fix-stdio-eof-drain
branch
2 times, most recently
from
July 15, 2026 21:13
ad43d63 to
d4fa0d6
Compare
Treat read-side EOF as a half-close so already-dispatched requests can finish while the connection still rejects new work and propagates real transport failures. Constraint: Preserve explicit close, write-error, and non-EOF read-error shutdown behavior. Rejected: Drain after every read failure | only clean EOF proves the peer stopped sending without invalidating in-flight responses. Confidence: high Scope-risk: narrow Directive: Keep EOF draining covered at the connection boundary rather than transport-specific callers. Tested: Focused race regression 100x, internal/jsonrpc2 race suite 10x, go test -v -race ./..., go test ./..., go vet ./..., gofmt, and diff checks. Not-tested: External conformance locally; the first rebased head passed both CI conformance suites before the test-only race fix.
ychampion
force-pushed
the
fix-stdio-eof-drain
branch
from
July 15, 2026 21:18
d4fa0d6 to
4b57174
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.EOFas 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:
go test ./internal/jsonrpc2 -run TestReadEOFAllowsInFlightResponseToDrain -count=1failed withWait returned error: server is closing: EOFgo test ./internal/jsonrpc2 -run TestReadEOFAllowsInFlightResponseToDrain -count=1go test ./internal/jsonrpc2 -count=1go test ./mcp -run 'Test(Stdio|Server|Client|InMemory)' -count=1\n-go test ./...\n-go vet ./...\n-git diff --check