Repository navigation
fix(dev): HTTP/1.1 keep-alive in HA proxy (run.py) - #1391
Conversation
The dev HA reverse proxy on :8500 left protocol_version at the stdlib HTTP/1.0 default, so it force-closed every client connection after one request. nix copy of a large closure pushes hundreds of objects over a small pool of HTTP/1.1 keep-alive connections; because the proxy refused to keep any connection alive, nix was forced to open a brand-new TCP connection per object -- thousands for a multi-GB closure. Under that churn (amplified by the default listen backlog of 5 and a ~1s-per-PUT stall from unanswered Expect: 100-continue), the accept loop stalls and intermittently nix's upload connection is reset before the proxy ever handles it, surfacing as 'curl error 56: Connection reset by peer' and aborting the whole copy. This is a second, distinct bug from the chunked-body fix in #1390 (which stays). Reproduced on a clean isolated ncps behind the real proxy and fix-validated: 3488 PUTs, 0 resets vs the unpatched proxy dying at PUT #2. Fix (dev-scripts/run.py proxy only; ncps unchanged): - Set ProxyHandler.protocol_version = 'HTTP/1.1' so client connections are persistent and reused; this also makes BaseHTTPRequestHandler auto-answer Expect: 100-continue, removing the per-PUT stall. - Frame forwarded responses for safe reuse: preserve Content-Length, treat 204/304/HEAD/1xx as bodiless, and send Connection: close when the body length is unknown so the client reads to EOF. - Raise the listener backlog (request_queue_size) above the default 5. Adds keep-alive/framing/Expect regression tests that drive the real run.py proxy via NCPS_RUN_PY (wired into the e2e-harness-unit check). Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
This change is part of the following stack: Change managed by git-spice. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughSummary by CodeRabbit
WalkthroughThe PR updates the dev HA reverse proxy to support HTTP/1.1 persistent connections and safe response framing. The proxy handler now uses HTTP/1.1 to enable keep-alive, detects bodiless and Content-Length-delimited responses, and signals Connection: close when body length is unknown. A larger server backlog absorbs connection bursts, and new regression tests verify keep-alive reuse, correct framing, and Expect: 100-continue handling. ChangesDev Proxy HTTP/1.1 Keep-Alive Fix
Sequence DiagramsequenceDiagram
participant Client
participant ProxyHandler
participant Backend
Client->>ProxyHandler: PUT/GET (HTTP/1.1)
ProxyHandler->>Backend: Forward request
Backend->>ProxyHandler: Response (with or without Content-Length)
alt Response has Content-Length or is bodiless (204/304/1xx/HEAD)
ProxyHandler->>Client: Forward with Connection: keep-alive
else Response body length unknown (no Content-Length, not bodiless)
ProxyHandler->>Client: Forward with Connection: close
Client->>Client: Read to EOF (body terminates)
end
Client->>ProxyHandler: Next request on same socket (if keep-alive)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
Comment |
There was a problem hiding this comment.
Code Review
This pull request updates the dev HA proxy in dev-scripts/run.py to support HTTP/1.1 persistent connections, which resolves connection reset issues during large uploads. It introduces response framing to safely handle keep-alive connections, increases the listener backlog, and adds comprehensive end-to-end tests and specifications. The review feedback correctly points out that the proxy should explicitly send a Connection: close header if the connection is already marked for closure, aligning with RFC 7230.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
When the proxy will close the connection for any reason — the client sent Connection: close, or it is an HTTP/1.0 client — RFC 7230 §6.3 requires the response to carry Connection: close so a keep-alive client does not assume the connection persists and reuse it (the same class of mis-framing this PR fixes). Previously the proxy only emitted it for an unframed (unknown-length) response; now it also emits it whenever self.close_connection is already set. Adds a regression test asserting a client Connection: close request gets Connection: close echoed even on a delimitable (204) response. Addresses Gemini review feedback on PR #1391 (thread PRRT_kwDONV6tZs6InEEx). Co-Authored-By: Claude Opus 4.8 <[email protected]>
Summary
A second, distinct dev-harness bug from the chunked-body fix in #1390 (which is necessary and stays). After #1390,
nix copyof a large closure (e.g. a ~9.35 GBnixos-system) to the:8500HA proxy still intermittently fails withcurl error 56: Connection reset by peer, aborting the whole copy on the first reset.Root cause: the proxy's
ProxyHandlerleftprotocol_versionat the stdlibBaseHTTPRequestHandlerdefault of HTTP/1.0, so it force-closed every client connection after one request.nix copypushes hundreds of objects over a small pool of HTTP/1.1 keep-alive connections; because the proxy refused keep-alive, nix was forced to open a brand-new TCP connection per object — thousands for a multi-GB closure. Under that churn (amplified by the default listen backlog of 5 and a ~1 s-per-PUT stall from unansweredExpect: 100-continue), the accept loop stalls and intermittently nix's upload connection is reset before the proxy ever handles it (curl error 56).Reproduced & fix-validated on a clean isolated ncps behind the real proxy: the unpatched proxy dies at PUT #2; the patched proxy completes 3,488 PUTs with 0 resets.
curl -vconfirmsHTTP/1.1 200+ "Connection left intact" (reuse).What changed (
dev-scripts/run.pyproxy only; ncps unchanged)ProxyHandler.protocol_version = "HTTP/1.1"— persistent, reused client connections; also makesBaseHTTPRequestHandlerauto-answerExpect: 100-continue, removing the per-PUT stall.Content-Length; treat204/304/HEAD/1xxas bodiless; sendConnection: closewhen the body length is unknown (e.g. backend chunked, stripped as hop-by-hop) so the client reads to EOF instead of mis-framing the next response.request_queue_size) above the stdlib default of 5, set before the socket is activated._faildrain, error logging).Test plan
task fmt(0 changed),task lint(0 issues),task test(all Go packages ok)Expect: 100-continueregression tests drive the realrun.pyproxy viaNCPS_RUN_PY; confirmed RED on HTTP/1.0, GREEN after the fixe2e-harness-unitnix check green (52 passed; +4 new tests)nix copyof the 9.35 GB closure through the patched proxy — 3,488 PUTs, 0 resets