Skip to content

fix(hono-server): drain in-flight requests on shutdown (P1-3)#1587

Merged
xuyushun441-sys merged 1 commit into
mainfrom
fix/graceful-http-drain
Jun 5, 2026
Merged

fix(hono-server): drain in-flight requests on shutdown (P1-3)#1587
xuyushun441-sys merged 1 commit into
mainfrom
fix/graceful-http-drain

Conversation

@xuyushun441-sys

Copy link
Copy Markdown
Contributor

Addresses launch-readiness P1-3. Verifying it first (per the checklist) flipped most of the finding:

Verification: "no SIGTERM/SIGINT handling" is a false positive

The kernel already does coordinated graceful shutdown:

  • Kernel.registerShutdownSignals() (called at start) handles SIGINT / SIGTERM / SIGQUITshutdown()performShutdown(): ordered plugin destroy (reverse), kernel:shutdown hook, then onShutdown handlers.
  • Bounded by a default 60s shutdownTimeout (the ≥60s grace floor the action asked for already exists).
  • cli/serve.ts boots through the kernel, so production inherits all of this.

The real, narrower bug — fixed

The standalone Hono server's close() called closeAllConnections(), which force-terminated in-flight requests mid-response. So a SIGTERM during a rolling deploy did drop active requests — but because of this, not missing signal handling.

Now close() drains:

  1. server.close() — stop accepting new connections, let active requests finish.
  2. closeIdleConnections() — release idle keep-alive sockets so the process exits promptly (not closeAllConnections, which kills active ones).
  3. A bounded drain window (default 10s, constructor-configurable, well under the kernel's 60s) force-closes only stragglers so shutdown can't hang.

Tests

+2 integration tests (real ephemeral-port server): a slow request completes through close() (drained, not reset); a hung request is force-closed within the drain window (shutdown doesn't wait it out). plugin-hono-server 40 tests green.

Residual (noted in the doc, not blocking)

  • Embedding adapters (express/fastify/…) intentionally leave signals to the host app.
  • Cluster/Redis close should be registered via kernel.onShutdown(...) by the cluster plugin — worth a quick confirm.

🤖 Generated with Claude Code

Verification reframed the launch-readiness P1-3 finding: the kernel already
handles SIGINT/SIGTERM/SIGQUIT with an ordered, 60s-bounded graceful shutdown
(registerShutdownSignals + performShutdown + onShutdown hooks), and serve.ts
boots through it — so "no signal handling" was a false positive.

The real, narrower bug: HonoHttpServer.close() called closeAllConnections(),
force-killing in-flight requests. Now it drains: server.close() + drain active,
closeIdleConnections() to release idle keep-alive, and a bounded drain window
(default 10s, < kernel 60s) force-closes only stragglers so shutdown can't hang.

+2 integration tests (drain completes a slow request; force-close bounds a hung
one). docs/launch-readiness.md P1-3 updated with the verification finding.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@vercel

vercel Bot commented Jun 5, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
spec Ready Ready Preview, Comment Jun 5, 2026 1:03am

Request Review

@github-actions github-actions Bot added documentation Improvements or additions to documentation tests tooling size/m labels Jun 5, 2026
@xuyushun441-sys xuyushun441-sys merged commit 93f97b2 into main Jun 5, 2026
12 checks passed
@xuyushun441-sys xuyushun441-sys deleted the fix/graceful-http-drain branch June 5, 2026 01:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size/m tests tooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants