Repository navigation
test(node): de-flake probe rate-limit reject close-code assertions (#1594) - #1595
Conversation
…1594) `probe_rate_limit_returns_rate_limited_close_code` and `probe_three_layer_limiter_rejects_per_peer` asserted that the client's `conn.closed()` resolves to `ApplicationClosed(0x10, <layer-label>)`, but occasionally observed `ApplicationClosed(0, "")` and failed. Root cause is a QUIC-layer race, not a handler bug. The ADR-005 reject path closes with `APP_ERR_RATE_LIMITED` + the layer-label reason bytes, but QUIC's `CONNECTION_CLOSE` is best-effort and unacknowledged. Over loopback the server can tear the connection down before that frame is delivered, and the client then observes quinn's implicit drop-close (code 0 / empty reason). The server already awaits `conn.closed()` after `close()`, but the closing side's `closed()` resolves immediately with `LocallyClosed`, so it provides no delivery guarantee — confirmed empirically: closing with a unique marker code still races an implicit 0 (~1/several-thousand under CPU load), proving the 0 is a separate teardown, not the reject frame losing its code. Since delivery cannot be guaranteed server-side, observe the rejection with a bounded retry (`observe_rate_limit_close`): retry a fresh rejected connection until the `0x10` + layer-label close is seen, treating the implicit-0 / transport teardown as a transient. The reason-byte assertion is preserved — a `0x10` close carrying the wrong label still fails immediately — so the tests keep proving the per-source / per-peer layering they exist for. The per-peer metric assertion relaxes from `== 1` to `>= 1` since a retried rejection also increments the counter. Verified: 60 loop runs (120 test executions) under 8 saturating CPU hogs, all green; cargo clippy -p decdn-node --tests and the full 933-test node suite pass. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Warning Review limit reached
Next review available in: 45 seconds Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Free Run ID: 📒 Files selected for processing (1)
Note 🎁 Summarized by CodeRabbit FreeYour organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login. Comment |
Coverage reportTotal: 80.23% (was 80.23%, ● 0.00%) — 56640/70597 lines No coverage data for changed Rust files. History
|
There was a problem hiding this comment.
Pull request overview
This PR addresses CI flakes in decdn-node probe loopback tests by making close-code assertions resilient to a documented QUIC CONNECTION_CLOSE delivery race, while still asserting the layer-label reason bytes to preserve coverage of the intended rate-limit layer.
Changes:
- Add
observe_rate_limit_closehelper that retries opening rejected connections until the expectedAPP_ERR_RATE_LIMITED (0x10)close code and expected layer label are observed. - Update the per-source and per-peer rate-limit tests to use a looped server accept task and the new bounded retry helper.
- Relax the per-peer rejection metric assertion from
== 1to>= 1to account for retries incrementing the counter.
Suppressed comments (1)
crates/node/tests/probe_loopback.rs:958
- If
client_ep.connect(...)fails, the endpoint created for this attempt is not explicitly closed before returning the error. Since this helper may retry connections, closing the endpoint on the error path keeps resource usage bounded and matches the cleanup pattern used throughout the test file.
let (client_ep, _) = local_endpoint(client_sk, vec![]).await?;
let conn = client_ep
.connect(target, ALPN_PROBE)
.await
.map_err(|e| anyhow::anyhow!("connect: {e}"))?;
Ok((client_ep, conn))
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Address PR #1595 review: in `observe_rate_limit_close`'s connect closures, a failed `client_ep.connect(...)` returned via `?` without an explicit `close().await`, so a retried attempt could leak a socket/driver task. Close the just-bound endpoint on the connect-error path, matching the file's cleanup convention. Co-Authored-By: Claude Opus 4.8 <[email protected]>
… budgets (#1830) Three of #1830's seven claims survive verification against main. The rest describe defects that #691, #1594/#1595 and #1779 already closed; the issue read historical rationale in comments as live defects, so those comments go too. `find_providers_negative_cache_expires_after_ttl` raced its own fixture: the injected 750ms TTL had to outlive a live loopback QUIC lookup before the suppression assertion read it, or the entry expired early and the provider was never suppressed. `tokio::time::pause` is unavailable there — the test is multi_thread over real QUIC, and the cache is anchored on `std::time::Instant` either way. Suppression now runs under the production TTL, which nothing in the test can outlive, and expiry is forced on the one key under test by re-recording it with a `Duration::ZERO` TTL: entries hold an absolute expiry, `shift_insert` updates an existing key in place, and `contains_active` reads `expiry <= now` as elapsed. That drops the 1100ms sleep with it — the test goes from 1.40s to 0.35s. Wall-clock TTL passage stays covered by the `negative_cache` unit tests and by `node_origin_pull`'s refusal suite. One 3s `round_timeout` served both the scenario where a round must time out and the two where a reachable peer must answer within it, making convergence an assertion about loopback latency under llvm-cov. Split into a convergence budget sitting just above `DHT_CLIENT_TIMEOUT` — so the per-RPC cap stays the binding constraint — and the short budget named only where a timeout is the point. The unreachable scenario's hang guard was 12s, exactly `MAX_LOOKUP_ROUNDS × 3s`: a guard on the implementation's own worst case, not headroom over it. It measures 6.4s (two rounds, not the one its comment claimed) and now has a guard that clears the ceiling. The file also tore endpoints down by hand — one unbounded `close().await` and a fire-and-forget spawn that let the test return mid-close — which is the hazard `support::shutdown` documents. It now routes through that helper, so a stalled close is bounded and named instead of parking until the nextest backstop, and a handler panic in the accept loop reaches the test that spawned it rather than being discarded by the abort. Last, `SHUTDOWN_TIMEOUT` equalled `ABANDON_DRAIN_CAP`, so one ceilinged abandon drain could consume the whole teardown budget before the first close was attempted and report `0/M endpoints closed` for a run in which nothing was wedged — a false stranded-driver reading on the channel that keeps #1675 visible. It now clears the drain cap. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
… budgets (#1830) (#1832) * test(node): de-flake the DHT integration suite and unpin two teardown budgets (#1830) Three of #1830's seven claims survive verification against main. The rest describe defects that #691, #1594/#1595 and #1779 already closed; the issue read historical rationale in comments as live defects, so those comments go too. `find_providers_negative_cache_expires_after_ttl` raced its own fixture: the injected 750ms TTL had to outlive a live loopback QUIC lookup before the suppression assertion read it, or the entry expired early and the provider was never suppressed. `tokio::time::pause` is unavailable there — the test is multi_thread over real QUIC, and the cache is anchored on `std::time::Instant` either way. Suppression now runs under the production TTL, which nothing in the test can outlive, and expiry is forced on the one key under test by re-recording it with a `Duration::ZERO` TTL: entries hold an absolute expiry, `shift_insert` updates an existing key in place, and `contains_active` reads `expiry <= now` as elapsed. That drops the 1100ms sleep with it — the test goes from 1.40s to 0.35s. Wall-clock TTL passage stays covered by the `negative_cache` unit tests and by `node_origin_pull`'s refusal suite. One 3s `round_timeout` served both the scenario where a round must time out and the two where a reachable peer must answer within it, making convergence an assertion about loopback latency under llvm-cov. Split into a convergence budget sitting just above `DHT_CLIENT_TIMEOUT` — so the per-RPC cap stays the binding constraint — and the short budget named only where a timeout is the point. The unreachable scenario's hang guard was 12s, exactly `MAX_LOOKUP_ROUNDS × 3s`: a guard on the implementation's own worst case, not headroom over it. It measures 6.4s (two rounds, not the one its comment claimed) and now has a guard that clears the ceiling. The file also tore endpoints down by hand — one unbounded `close().await` and a fire-and-forget spawn that let the test return mid-close — which is the hazard `support::shutdown` documents. It now routes through that helper, so a stalled close is bounded and named instead of parking until the nextest backstop, and a handler panic in the accept loop reaches the test that spawned it rather than being discarded by the abort. Last, `SHUTDOWN_TIMEOUT` equalled `ABANDON_DRAIN_CAP`, so one ceilinged abandon drain could consume the whole teardown budget before the first close was attempted and report `0/M endpoints closed` for a run in which nothing was wedged — a false stranded-driver reading on the channel that keeps #1675 visible. It now clears the drain cap. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> * test(client-pull): drive the interval-flush count off the virtual clock `interval_flush_persists_progress_before_completion` asserted a flush count that only held if the runner cooperated. The work future sleeps 130ms on the real clock against a 20ms flush interval, and `drive_with_interval_flush` selects `biased` with completion first — so a runtime descheduled past the work's deadline finds it already elapsed and returns, having flushed as few as once. CI hit exactly that: `got 1`. `start_paused` removes the wall clock. The interval's deadlines become the only thing that can advance time, so the count is arithmetic: the immediate first tick is consumed before the loop, leaving 20..=120ms inside the work's 130ms. Six, every time — which lets the assertion tighten from `> 1` to an exact count, and that also pins the single-writer property the test claims to check, since a work future that flushed too would push it over six. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> * test(node,client-pull): close the #1832 review findings Six findings from the review of #1832. Two are behavioral; four correct prose that asserted things the code does not do. `TestServer::shutdown` now verifies its postcondition. `support::shutdown` warns rather than fails on a deadline breach, because the stranded-driver half of that breach is the known-open #1675. For teardown that is right. At the one call site in `find_providers_tolerates_unreachable_peer` it is not teardown but the scenario's PRECONDITION: on a breach the dead peer stays up and the test passes having exercised nothing. `Endpoint::is_closed` keeps that failure loud. `CONVERGENCE_ROUND_TIMEOUT > DHT_CLIENT_TIMEOUT` moves from prose into a `const _: () = assert!`. The ordering is the constant's whole purpose — a `DHT_CLIENT_TIMEOUT` raised past it silently restores the round drain pre-empting a peer the RPC layer still wants, with both convergence scenarios back to measuring loopback latency and still green. Same shape as `node_origin`'s `REFUSAL_SUPPRESSION_TTL` ceiling assertion. The unreachable scenario spends ONE round, not two. Measured by varying the constant: at 3s the test costs 6.4s, at 1s it costs 4.3s — a 2s cut buys 2.1s, so one round is in the budget and the remaining ~3.4s is fixture. The routing table holds two peers and `alpha` is 3, so round one queries both and the next pass breaks on an empty batch BEFORE arming a second round. `UNREACHABLE_HANG_GUARD` is unchanged: it is sized against the `MAX_LOOKUP_ROUNDS` ceiling, which is what a hang guard should clear. `with_capacity_and_ttl`'s doc no longer prescribes against three of its own module's unit tests. TTL semantics and cache-wide TTL quantity are both legitimate subjects for the seam; only an entry expired as a PRECONDITION wants the `Duration::ZERO` idiom instead. `SHUTDOWN_TIMEOUT` drops the claim to track `runtime::SHUTDOWN_DEADLINE` — the values coincide but nothing couples them, and that constant is private to another crate. `ABANDON_DRAIN_CAP` is the sole derivation. The mechanism is corrected too: the drain runs on the pull leg's own runtime thread, so the first close IS attempted and blocks inside it. The `driver.rs` test does not pin the single-writer property: its work future is a bare `sleep` holding no `&store`, so it cannot flush and the count cannot detect one that does. The virtual clock also advances to the work's own sleep deadline, not only the interval's. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Fixes #1594.
Problem
probe_rate_limit_returns_rate_limited_close_codeandprobe_three_layer_limiter_rejects_per_peer(crates/node/tests/probe_loopback.rs) assert the client'sconn.closed()resolves toApplicationClosed(0x10 /* APP_ERR_RATE_LIMITED */, <layer-label>), but occasionally observedApplicationClosed(0, "")and failed on CI (run 30907917266, passed on re-run).Root cause — a QUIC-layer race, not a handler bug
The ADR-005 reject path already closes with
APP_ERR_RATE_LIMITED+ the layer-label reason bytes and awaitsconn.closed()afterward. But QUIC'sCONNECTION_CLOSEis best-effort and unacknowledged, and quinn resolves the closing side'sclosed()immediately withLocallyClosed— so that server-side await is not a delivery guarantee. Over loopback under scheduling pressure the server can drop the connection before the frame reaches the client, and the client then observes quinn's implicit drop-close (code0/ empty reason).I confirmed this empirically with an in-process stress harness under CPU load: closing the server side with a unique marker code (
0x77/"MARKER") still produced a client-observedApplicationClosed(0, "")~1/several-thousand. That proves the0is a separate teardown racing the reject frame, not the reject frame losing its code — so the reject path cannot be made to guarantee delivery from the server side (this is the "genuinely unavoidable at the QUIC layer" case the issue anticipated).Fix
Observe the rejection with a bounded retry (
observe_rate_limit_close): open a fresh rejected connection (up to 8 attempts) until the0x10+ layer-label close is seen, treating the implicit-0/ transport teardown as a transient to retry. Crucially, the reason-byte assertion is kept — a0x10close carrying the wrong label fails immediately — so the tests still prove the per-source / per-peer layering they exist for (distinguishing it from the also-0x10global / per-IP cap). The per-peer/metricsassertion relaxes from== 1to>= 1, since a retried rejection also increments the counter. Server code (handlers/probe.rs) is unchanged.Verification
cargo clippy -p decdn-node --testsclean;cargo fmt --checkclean.🤖 Generated with Claude Code