Repository navigation
Conversation
Wait for the Streamable HTTP grace period after the listener closes. Close remaining connections on a shutdown error and preserve the cause for the CLI. Cover in-flight responses, deadline expiry, startup cancellation, and listener errors.
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
Coordinating signal handling, request draining, forced cancellation, and timeout-driven exit status changes affects in-flight responses and process supervision, requiring human review.
No open issues 🎉
What changed in this PR
Fixes the self-hosted Streamable HTTP CLI shutdown lifecycle so active requests can finish before the process exits, without changing MCP tools or APIs.
Changes:
- Waits for both the HTTP serve loop and graceful shutdown to finish.
- Preserves the five-second grace period, force-closes remaining connections on failure, and returns shutdown errors.
- Adds deterministic tests for response draining, timeout cancellation, listener errors, and cancellation before serving.
| File | Description |
|---|---|
pkg/http/shutdown_test.go |
Tests graceful draining and shutdown failure paths using in-memory connections. |
pkg/http/server.go |
Coordinates serving and shutdown, enforces the grace deadline, and propagates errors. |
Review effort: Max (adaptive)
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.
Summary
Wait for active Streamable HTTP requests to finish during CLI shutdown. If the five-second grace period expires, close the remaining connections and return the shutdown error.
Why
On
SIGTERMorSIGINT,RunHTTPServerstartedhttp.Server.Shutdownin a goroutine. Go closes the listener before waiting for active handlers, soListenAndServereturnedhttp.ErrServerClosedwhile the drain was in progress. The CLI then loggedserver stopped gracefullyand could exit before the SDK wrote the MCP response. A client could receive EOF even when its GitHub API request could have completed inside the grace period. GoServer.ShutdowndocumentationThe reproduction used the Linux CLI from
4e6e6c053e48, a normal MCPget_mecall, and a local GitHub API stub. The stub held/api/v3/useruntil afterSIGTERMclosed the listener. With the response still blocked, the original process logged graceful shutdown and exited with status 0. The caller received EOF. Under the same sequence, the fixed process waited for the stub, delivered JSON-RPC result ID 42, and then exited with status 0.With the stub held past the full grace period, the fixed CLI reported
context deadline exceededand exited with status 1 after approximately five seconds. The MCP client connection closed and the GitHub stub observed request cancellation.What changed
net/httphandlers,net.Pipe, andtesting/synctest. The tests cover response delivery during drain, connection closure and request cancellation at the grace deadline, listener errors, and cancellation before serving. Restoring the old shutdown ordering in a temporary overlay made the drain and deadline regressions fail on their expected assertions.MCP impact
Prompts tested (tool changes only)
The transport reproduction uses the existing
get_metool against a loopback API stub.Security / limits
Tool renaming
Lint & tests
./script/linton Linux using the pinned golangci-lint v2.14.0../script/test(go test -race ./...) on Linux.go test -run '^TestServeHTTP' -count=100 -timeout 60s ./pkg/http,go test -v ./..., andUPDATE_TOOLSNAPS=true go test ./.... The verbose run passed 32 packages, 1,207 top-level tests, and 7,825 subtests. The snapshot pass produced no tracked changes.go test -race -run '^TestServeHTTP' -count=100 -timeout 60s ./pkg/http,go mod tidy -diff, and a CLI build. The CLI also built on Windows. The signal-to-response reproduction ran on Linux.Docs
script/generate-docsreproduced all five checked-in documentation files it generates.Skills
Streamable HTTP CLI mode was introduced in #1849.
AI assistance was used to investigate and reproduce the defect, author the fix and tests, review the diff, and draft this description.