fix(serv): bound shutdown so Ctrl-C exits when SSE/keep-alive conns linger#583
Merged
amitdeshmukh merged 1 commit intomasterfrom Apr 29, 2026
Merged
fix(serv): bound shutdown so Ctrl-C exits when SSE/keep-alive conns linger#583amitdeshmukh merged 1 commit intomasterfrom
amitdeshmukh merged 1 commit intomasterfrom
Conversation
…inger s.srv.Shutdown was called with context.Background(), so any in-flight HTTP connection (most commonly an MCP SSE stream) blocked shutdown forever. "shutdown complete" was also logged from RegisterOnShutdown, which fires asynchronously, so the log line printed even though the process never exited. Give Shutdown a 10s timeout, fall back to srv.Close() on timeout, and run closeFn/cache/db cleanup inline after Shutdown returns so the final log reflects reality. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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
s.srv.Shutdownwas called withcontext.Background(), so any in-flight HTTP connection (most commonly an MCP SSE stream at/api/v1/mcp, but also idle keep-alives) blocked shutdown forever — Ctrl-C left the process hung."shutdown complete"was logged from insideRegisterOnShutdown, which fires asynchronously whenShutdownis called. The line printed even though the server hadn't actually exited, masking the hang.Fix
Shutdowna 10s timeout; on timeout fall back tos.srv.Close()to force-drop lingering connections.RegisterOnShutdownand runcloseFn/cache/db cleanup inline afterShutdownreturns, so the final"shutdown complete"log reflects reality."shutdown signal received"log on SIGINT for visibility.Single-file change,
serv/serv.goonly.Test plan
go build ./serv/...passesgo vet ./serv/...passesgraphjin serveagainst a remote Postgres, open an MCP client (or hold an SSE connection), Ctrl-C — process should exit within ~10s instead of hanging🤖 Generated with Claude Code