Skip to content

fix(serv): bound shutdown so Ctrl-C exits when SSE/keep-alive conns linger#583

Merged
amitdeshmukh merged 1 commit intomasterfrom
fix/server-shutdown-hang
Apr 29, 2026
Merged

fix(serv): bound shutdown so Ctrl-C exits when SSE/keep-alive conns linger#583
amitdeshmukh merged 1 commit intomasterfrom
fix/server-shutdown-hang

Conversation

@amitdeshmukh
Copy link
Copy Markdown
Collaborator

Summary

  • s.srv.Shutdown was called with context.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 inside RegisterOnShutdown, which fires asynchronously when Shutdown is called. The line printed even though the server hadn't actually exited, masking the hang.

Fix

  • Give Shutdown a 10s timeout; on timeout fall back to s.srv.Close() to force-drop lingering connections.
  • Drop RegisterOnShutdown and run closeFn/cache/db cleanup inline after Shutdown returns, so the final "shutdown complete" log reflects reality.
  • Also added a "shutdown signal received" log on SIGINT for visibility.

Single-file change, serv/serv.go only.

Test plan

  • go build ./serv/... passes
  • go vet ./serv/... passes
  • Manual: graphjin serve against a remote Postgres, open an MCP client (or hold an SSE connection), Ctrl-C — process should exit within ~10s instead of hanging
  • Manual: Ctrl-C with no active clients — process should exit immediately as before

🤖 Generated with Claude Code

…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>
@amitdeshmukh amitdeshmukh merged commit 9a7d341 into master Apr 29, 2026
5 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