Repository navigation
Fix lost download records and expire idle MCP sessions (v1.6.2) - #6
Merged
Merged
Conversation
The /dl handler recorded download history in a goroutine using
r.Context(). net/http cancels that context as soon as ServeHTTP
returns, so the insert raced the cancellation and often failed with
"recording download: context canceled". Use
context.WithoutCancel(r.Context()) plus a 10s timeout, and capture
RemoteAddr/User-Agent before the goroutine starts.
A client that disconnects mid-download is now logged at INFO
("download aborted by client") instead of ERROR. Such downloads are
still not recorded.
The download body was already streamed (S3 GetObject body -> io.Copy
-> ResponseWriter, no middleware on /dl). New tests pin that down: a
64 MiB object behind a reader that fails if more than 1 MiB is read
but not yet written, a test that the record survives request
cancellation, and a test for client disconnect (body closed, read
stopped, nothing recorded).
CLAUDE.md: correct "MCP server never touches file data". With
s3.proxy configured, /dl and /ul stream file bytes through the server.
mcp-go keeps per-session Streamable HTTP state forever unless WithSessionIdleTTL is set, so clients that disconnect without a DELETE leak memory. In production the container hit its 128Mi limit and was OOM-killed 13 times between April and November 2026.
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.
Two production fixes behind repeated OOM kills and missing download stats.
Expire idle MCP sessions after 30 minutes. mcp-go keeps per-session Streamable HTTP state forever unless
WithSessionIdleTTLis set, so clients that disconnect without a DELETE leak memory. The production container hit its 128Mi limit and was OOM-killed 13 times between April and November 2026 (kernel: anon-rss ~127 MB at each kill).Record proxy downloads with a detached context.
GET /dlrecorded the download in a goroutine usingr.Context(), which net/http cancels once the handler returns, so records were lost (failed to record download: context canceled). Nowcontext.WithoutCancelwith a 10s timeout; request fields are read before the goroutine starts./dlalready streamed (io.Copyfrom S3); a new test proves it with a 64 MiB object and a 1 MiB buffering cap. Client disconnects are logged at INFO instead of ERROR. CLAUDE.md no longer claims the server never touches file data.go build,go vet,go test ./...andgo test -race ./internal/proxy/pass.🤖 Generated with Claude Code