Skip to content

fix(http): raise keep-alive timeout above proxy idle timeouts - #473

Merged
tianzhou merged 1 commit into
mainfrom
claude/dreamy-planck-l3cnyx
Oct 13, 2026
Merged

tianzhou merged 1 commit into
mainfrom
claude/dreamy-planck-l3cnyx

Conversation

@tianzhou

Copy link
Copy Markdown
Member

Fixes #472

Problem

The HTTP transport created its server with http.createServer(app) and kept Node's default keepAliveTimeout of 5s. Proxies that pool upstream connections (AWS ALB, API Gateway VPC links, nginx keepalive) hold them idle for 60s. When such a proxy writes a request into a socket Node is closing at that moment, the proxy answers the client with its own 502/503 and the request never reaches DBHub's logs.

Fix

Set keepAliveTimeout to 65s and headersTimeout to 66s so the proxy is always the side that closes an idle connection. Node requires headersTimeout to be strictly greater than keepAliveTimeout, hence the 1s gap. The values are hard-coded on purpose; no new flag or env var.

  • src/utils/http-keep-alive.ts: constants plus configureHttpKeepAlive(server) with the rationale in comments
  • src/server.ts: call it right after http.createServer(app)
  • src/utils/__tests__/http-keep-alive.test.ts: asserts the values are applied and that the headers timeout stays above keep-alive, so a future refactor of the server setup can't silently drop them

Verification

Ran the reproduction script from the issue against the built server. Before, the server closed the idle socket at ~6s and the second request got a fresh connection. After:

200 reused=false
200 reused=true

The socket survives the 10s idle and the second request reuses it.

pnpm exec vitest run on the new test plus the HTTP bind-host and JSON-RPC integration suites: 17 passed. The connector integration suites need Docker and were not run here.

🤖 Generated with Claude Code

https://claude.ai/code/session_013piqks7dS3HsaAKC6YVWLN


Generated by Claude Code

The HTTP transport kept Node's default keepAliveTimeout of 5s. Proxies
that pool upstream connections (AWS ALB, API Gateway VPC links, nginx)
hold them idle for 60s, so a request written into a socket Node was
closing surfaced as a proxy 502/503 that never reached DBHub's logs.

Set keepAliveTimeout to 65s and headersTimeout to 66s so the proxy is
always the side that closes an idle connection. Hard-coded on purpose;
no new flag.

Fixes #472

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013piqks7dS3HsaAKC6YVWLN
Copilot AI balanced review requested due to automatic review settings October 13, 2026 14:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The tests do not cover the production server wiring and therefore cannot catch removal of the configuration call.

1 open finding
What changed in this PR

Raises HTTP keep-alive timeouts to avoid proxy-generated 502/503 errors.

Changes:

  • Adds centralized keep-alive timeout configuration.
  • Applies it to the HTTP server.
  • Adds unit tests for configured values.
File Description
src/​utils/​http-keep-alive.ts Defines and applies HTTP timeout values.
src/​server.ts Configures the production HTTP server.
src/​utils/​__tests__/​http-keep-alive.test.ts Tests timeout constants and helper behavior.

🧠 Review effort: Balanced


💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

} from "../http-keep-alive.js";

describe("configureHttpKeepAlive", () => {
it("raises keep-alive above a 60s proxy idle timeout (issue #472)", () => {
@tianzhou
tianzhou merged commit b614c0d into main Oct 13, 2026
3 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.

HTTP transport: default 5s keep-alive causes intermittent 502/503s behind load balancers and API gateways

3 participants