Skip to content

Fix lost download records and expire idle MCP sessions (v1.6.2) - #6

Merged
glani merged 2 commits into
mainfrom
stream-downloads
Nov 11, 2026
Merged

glani merged 2 commits into
mainfrom
stream-downloads

Conversation

@glani

@glani glani commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator

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 WithSessionIdleTTL is 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 /dl recorded the download in a goroutine using r.Context(), which net/http cancels once the handler returns, so records were lost (failed to record download: context canceled). Now context.WithoutCancel with a 10s timeout; request fields are read before the goroutine starts.

/dl already streamed (io.Copy from 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 ./... and go test -race ./internal/proxy/ pass.

🤖 Generated with Claude Code

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.
@glani
glani merged commit 33e359a into main Nov 11, 2026
12 checks passed
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.

1 participant