Repository navigation
docs(rate-limit): record that a failed backend dial keeps the per-(cluster, IP) slot - #1528
Merged
Merged
Conversation
FlorentinDUBOIS
requested review from
Wonshtrum and
llenotre
as code owners
September 25, 2026 11:29
…uster, IP) slot `Router::plan_connect` claims a `(cluster, source-IP)` slot after the `cluster_ip_at_limit` gate and before backend selection, and none of the six fallible exits that follow the claim releases it. Since #1519 split the connect path those exits sit in two functions — the two pool-reuse refusals stay in `Router::plan_connect`, the four on the fresh-dial path moved to `Mux::dial_backend` — but the ordering is unchanged and `Mux::ready_inner` joins both halves into one `Result` with `and_then`, so they still share one error arm. The only release is `SessionManager::untrack_all_cluster_ip`, from session teardown. The unpaired claim reads like an oversight, so state that it is a decision and what the decision rests on. Measured on the error path rather than assumed. Every post-claim exit reaches the `BackendConnectionError` arm of the pending-link loop in `Mux::ready_inner`, which answers the stream from the template registry instead of retrying, and every built-in answer template carries `Connection: close`. That clears `HttpContext::keep_alive_frontend`, and that one bit is what ends the frontend connection: H1 closes after the answer flushes instead of taking the keep-alive reset, H2 sends a final GOAWAY when the failed stream was the only one and the advisory GOAWAY of a graceful drain otherwise, and a draining connection refuses new peer streams so the client cannot extend the window. Raw TCP never reaches an answer — any error out of `TcpSession::connect_to_backend` closes the session in the same event-loop pass. So the slot comes back with the connection, and the "a failed dial leaks a slot until an unrelated timeout" reading does not hold in the shipped configuration. Two branches are written down beside it. A backend that is registered and healthy-status but down does not fail on the dial at all, because `Backend::try_connect` is non-blocking: the refusal arrives later as a backend HUP and the stream retries, holding one slot — not one per attempt, the re-track is idempotent — for at most `CONN_RETRIES` attempts. And a custom answer template that omits `Connection: close` — the keep-alive opt-in the 429 template already documents — holds the slot for the connection's whole lifetime. No behaviour change: `lib/src/server.rs` gains only `///` lines. The citation re-anchor in `doc/lifetime_of_a_session.md` is that insertion shifting the file by 69 lines; each cited line was re-resolved by its text at the base revision and its enclosing `fn`. Two citations to the `accept_queue.backpressure` gauge become symbol citations because the shift made this changeset reuse line 594 for different code. Refs: #1521 Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
force-pushed
the
fix/cluster-ip-slot-on-failed-dial
branch
from
September 25, 2026 12:55
d366b50 to
914bc65
Compare
This was referenced Sep 25, 2026
FlorentinDUBOIS
added a commit
that referenced
this pull request
Sep 25, 2026
…er-pool span (#1533) `doc/lifetime_of_a_session.md` cited a buffer-pool gauge block as the evidence for the 1 Hz `accept_queue.saturated_seconds` ticker, in the section 3.3 narrative and again in the metric inventory. The ticker is fifteen lines further down, in the `ACCEPT_SATURATION_TICK` block of `Server::run`; both sites now cite that symbol. The companion span covering the constant's own declaration and doc comment was already correct and is kept as a range. Every gate passed on the defect, each for a defensible reason: the cited lines resolve and are not blank, so rule 1 is satisfied, and the cited text never changed, so rule 2 has nothing to compare — #1528 re-anchored the number faithfully while it was already wrong. A faithful re-anchor of a wrong citation is indistinguishable from a faithful re-anchor of a right one. That is #1447 seen from the other side: there a rule fired on a citation that was correct, here every rule stayed silent on one that is not. The fix is a symbol rather than a corrected number because a number that has survived two faithful re-anchors while wrong is exactly the case the convention exists for. Sweeping all eighteen cited spans in the document by hand found three more of the same class, none of them in the metric inventory, which is clean. The write-only-shutdown pair both landed inside the failed-upgrade branch whose own comment says the front socket is unreachable — the inverse of the claim they support — and now cite the `Shutdown::Write` block of `HttpsSession::close` and its mirror in `HttpSession::close`. The SoftStop / HardStop citation straddled two functions while containing neither verb, and now cites `Server::read_channel_messages_and_notify`. Whether `--audit` can be made to catch the class was measured, and the answer is no. The candidate is not a new rule but a wider prose window on the existing symbol signal, which stayed silent only because the citation sits mid-line under the sentence naming the metric, so both spans were declined rather than examined. Widening reports one real defect per six additions, or two per thirteen for the literal rule the issue proposed, against the six-in-thirteen rate the mode measures for itself and prints in its own banner; the literal rule also silences three correct-citation findings it reports today. The variants that do fire on this citation fire by a one-line margin — the window is eight and the ticker's own comment naming the metric sits nine lines past the wrong span's end. Those numbers, the second silencer behind them and that margin are recorded in `doc/README.md` and in the script's header. The script's behaviour is unchanged; the diff to it is comment-only. Documentation only: no `.rs` file changes. Closes #1531 Signed-off-by: Florentin Dubois <[email protected]>
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.
Answers the measurement #1521 asks for, and takes the decision it leads to. No
production code changes:
lib/src/server.rsgains only///lines.Rebased onto
mainafter #1519 landed, and re-derived against it rather thansearch-and-replaced — the structural claim below is still true, but it is now true
across two functions, and a reader needs to know which exits live where to check it.
The measurement
Router::plan_connectclaims a(cluster, source-IP)slot after thecluster_ip_at_limitgate and before backend selection. Six fallible exitsfollow that claim, not the four the issue lists — the fresh connection's
start_streamrefusal and theregister_socketrollback are also post-claim — andnone of them releases. Since #1519 they sit in two functions:
Router::plan_connectMaxSessionsMemoryRouter::plan_connectMaxSessionsMemory?onRouter::backend_from_requestMux::dial_backendBackend(_)Connection::new_h2_clientpool exhaustionMux::dial_backendMaxBuffersMux::dial_backendMaxSessionsMemoryL7Proxy::register_socketfails (rolls back gauges, slab, epoll — not the slot)Mux::dial_backendMaxSessionsMemoryThe split moved no ordering and did not fork the error path:
Mux::ready_innerjoins the plan and the dial with
and_then, so both halves land in oneResultand one error arm. That arm holds 11
set_default_answer*calls and zerooccurrences of
SessionResult— nothing there closes a session directly.What closes the connection is the answer, not the error. Every built-in
template in
lib/src/protocol/kawa_h1/answers.rscarriesConnection: close, soset_default_answer_with_retry_afterclearsHttpContext::keep_alive_frontend.ConnectionH1::writabletakesdefer_close_for_tls_flushinstead of the keep-alive reset. One flush.close_frontendis raised as thestream retires and
ConnectionH2::goaway(NoError)is sent. Same pass, modulo theTLS flush.
ConnectionH2::graceful_goawaysends theadvisory GOAWAY instead, and a draining connection refuses new peer streams
(
RefusedStream). So a failed dial on one stream does not leave the connectionserving indefinitely: the window is the remaining lifetime of the streams already
open, and the client cannot extend it. The final GOAWAY goes out from
finalize_writewhen the last stream retires. Theh2_graceful_shutdown_deadline_secondsforced close does not bound this — itis armed only from the worker soft-stop path.
backend_from_cluster_id). AnyErrbecomesSessionResult::Closein the same event-loop pass, andTcpSession::closeuntracks directly.
Two branches where the window is longer, both written down:
Connection: close— the keep-alive opt-inthe 429 template already documents — never clears
keep_alive_frontend, so noH1 close and no GOAWAY. The slot is then held for the connection's whole
lifetime.
ConnectionH2::try_recycle_server_streamdefers retirement while the client hasnot sent END_STREAM, so the GOAWAY waits with it. Bounded by
h2_stream_idle_timeout_seconds/cancel_timed_out_streams, and it costs oneslot for one held connection — the same arithmetic as a healthy connection.
A backend that is registered and healthy-status but down may not fail on the dial
at all.
Backend::try_connectis non-blocking: a synchronous refusal (the commoncase for a closed port on loopback) surfaces as
BackendError::ConnectionFailuresand takes the answer path, while an
EINPROGRESSconnect returnsOkand itsrefusal arrives later as a backend HUP, so the stream retries through
EndStreamAction::Reconnect. The re-track is idempotent, so one slot — not oneper attempt — is held for at most
CONN_RETRIES(3) attempts, each bounded byconnect_timeout(default 3 s).The decision
The short-window reading holds in the shipped configuration, so this documents the
claim rather than pairing a release with it. Releasing on failure would loosen the
cap under exactly the conditions a client can induce, and would buy little: the
connection that provoked the failure is closed by the answer it provoked, so it
cannot accumulate slots either way.
What changed
lib/src/server.rs— the reasoning atSessionManager::track_cluster_ip, so theunpaired claim reads as a decision.
///lines only.doc/rate-limit-design.md— a new §3.2.1 under Counter discipline.doc/lifetime_of_a_session.md— citation re-anchor forced by the 69-lineinsertion into
lib/src/server.rs. Each cited line was re-resolved by its text atthe base revision and its enclosing
fn. Two citations to theaccept_queue.backpressuregauge are symbol citations rather than numbers,because the shift makes this changeset reuse line 594 for different code.
No test: the outcome is documentation, and there is no behaviour to pin.
Closes #1521