node-http-proxy-ttfb-timeout
Installation
SKILL.md
Node.js HTTP Proxy TTFB Timeout (Keep-Alive Safe)
Problem
When implementing HTTP proxy/reverse-proxy code with TTFB (time-to-first-byte) timeouts, socket-based timeout logic fails on keep-alive connections. The first request works fine, but subsequent requests on reused sockets hang forever even though the upstream is dead.
Context / Trigger Conditions
- First HTTP request through proxy succeeds
- Second request (on same keep-alive connection) hangs indefinitely
- Upstream is a tunnel (cloudflared, ngrok) or service that can go offline
- Using
socket.setTimeout()orproxyReq.on('socket', ...)for timeout logic - Timeout callback never fires for reused connections
- Half-open TCP connections (remote closed, local doesn't know)