Repository navigation
fix(connpool): a request lost to an upstream's idle close goes out again - #574
Merged
Merged
Conversation
Since #556 and #559 the static server's forwards, the public link router and the hub's way to a daemon keep idle HTTP/1.1 connections, with no bound on how long. An upstream closes a connection idle for its keep-alive timeout (Node.js 5 s, gunicorn 2 s); a request written on it just as the close arrives fails although the upstream never answered. hyper hands such a request back unsent only when it noticed the close first; otherwise it reports "connection closed before message completed", `Pool::send` gave up, and the proxy answered 502. `connpool::Pool::send` now sends a request that failed on a kept connection once more on a new one when hyper hands it back unsent, or when the upstream closed the connection before any answer and the request can be repeated: an idempotent method (RFC 9110 §9.2.2) without a body, as browsers and Go's net/http do. A request with a body, a POST, or one that failed on a new connection is not sent twice. A connection idle for 4 s or longer is not reused at all, below Node.js's 5 s, so the race is rare where it is most common. The link router and the service proxy (`devstack-daemon`, `proxy.rs`), which kept its own pool with the same flaw, now send through `Pool::send`; the proxy forgets a drained instance's connections with `Pool::forget`. The hub's `daemon_send` resends a repeatable request at once on such a close instead of after its 100 ms pause. Bug-Class: stale-pooled-connection Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
Since #556 and #559, connections to a static forward's target, a public link's service and a daemon are kept (
devstack_node::connpool), with no bound on how long one sits idle. A request written on a kept connection just as the upstream closed it for its keep-alive timeout (Node.js after 5 s) failed with "connection closed before message completed": hyper gives the request back only when it noticed the close first. The static server, the link router and the service proxy answered 502. Found in a code review before 0.49.4 (documented internally).closed_unanswered), for requests safe to send twice (replay: idempotent methods without a body). A request with a body, or one that failed on a new connection, is not sent twice.connpool::Pool; draining an instance forgets its port as before. The hub'sdaemon_sendresends a repeatable request at once when a reused connection was closed unanswered.Verification
stale-pooled-connectionconnpool::tests::a_kept_connection_the_upstream_closes_is_retried_on_a_new_one:Err("connection closed before message completed")instead ofOk(200)(a test upstream that closes on the next request).a_request_with_a_body_or_not_idempotent_is_not_sent_twicefails; retrying on a new connection too:a_request_on_a_new_connection_is_not_sent_twicefails.cargo test -p devstack-node,-p devstack-daemon,-p devstack-hubpass; clippy clean.Pool::send), link router and service proxy moved onto it, hub patched. One-shot connections (tls.rs,daemon_request_once, node handshakes) reuse nothing. ureq's own pools not checked.🤖 Generated with Claude Code