Skip to content

fix(node): read the 0x10 RATE_LIMITED close requester-side instead of scoring Unreachable - #1993

Merged
alpergundogdu merged 2 commits into
mainfrom
claude/github-issue-1986-463d78
Sep 11, 2026
Merged

alpergundogdu merged 2 commits into
mainfrom
claude/github-issue-1986-463d78

Conversation

@yigitdot

Copy link
Copy Markdown
Contributor

Closes #1986.

Problem

A node that sheds load at the transport closes the connection (or resets the stream) with APP_ERR_RATE_LIMITED (0x10) and a layer label — and waits 250 ms so the peer sees it. The requester never read it: client-pull flattened every transport error to anyhow!("open_bi failed: {e}"), so node_origin's probe_candidate and pull_verdict fell through to Outcome::Unreachable — a 0.0 EWMA sample for a peer that answered, and one every prober in a global-full window recorded simultaneously. The handler-level shed (Overloaded → signed NotFound) was already exonerated as RefusalVerdict::Transient; the two layers disagreed on the same condition.

Fix (issue's option 1)

  • decdn-client-pull: new rate_limited module — UpstreamRateLimited { label } sentinel and rate_limit_shed, which walks an error's source() chain for an ApplicationClosed / ReadError::Reset / WriteError::Stopped carrying 0x10, including through FrameError::Io's io::Error (whose inner stream error is reachable only via get_ref(), not source()). Every connect / open_bi / write_frame / read_frame site in probe.rs and lib.rs routes through transport_error; every existing message string is unchanged.
  • node_origin: the sentinel gets exactly what the handler-level shed gets — the (peer, hash) pair is suppressed for REFUSAL_SUPPRESSION_TTL (30 s), no Outcome is recorded. probe_candidate checks it before the Unreachable fallback; pull_verdict maps it to a new PullVerdict::RateLimited (→ PullMiss::Clean).
  • Metric: decdn_node_upstream_rate_limited_total, the only trace the event leaves at the default RUST_LOG=info.
  • ADR 013 0x10 row names the requester-side consumer.

Tests

  • rate_limited unit tests: label carried off a connection close, None for a stream reset, non-0x10 codes ignored, recovery through FrameError → io::Error → ReadError/WriteError nesting, and downcast_ref through added context.
  • node_origin unit tests: pull_verdict → RateLimited through context layers, PullMiss::Clean, sentinel added to the downcast-survival and every-verdict enumerations.
  • probe_loopback: probe_once against a pre-drained per-source ConnectionLimiter returns UpstreamRateLimited { label: Some("per-source") } (bounded retry over the flaky: probe_rate_limit_returns_rate_limited_close_code races on the application close code (sees 0 instead of 16) #1594 close-frame race, same as the sibling test).

Accepted residue

A global-full shed deliberately skips the node's close ack-wait (probe.rs — a flood would park a task per rejection), so it can still arrive as a bare drop and score Unreachable. The metric doc calls this out. DHT emitters need no consumer: the DHT client records no reputation.

Out of scope, not changed: decdn fetch still counts a rate-limited probe under "unreachable" in its terminal message (fetch.rs drops the error with res.ok()) — cosmetic, follow-up.

🤖 Generated with Claude Code

… scoring Unreachable

A node that sheds load at the transport closes the connection (or resets
the stream) with APP_ERR_RATE_LIMITED and a layer label, and waits 250 ms
so the peer sees it. The requester never read it: client-pull flattened
every transport error to a string, so node_origin's probe_candidate and
pull_verdict fell through to Outcome::Unreachable — a 0.0 EWMA sample for
a peer that answered, and one every prober in a global-full window
recorded at once. The handler-level shed (Overloaded → signed NotFound)
was already exonerated as RefusalVerdict::Transient; the two layers
disagreed on the same condition.

client-pull gains `UpstreamRateLimited`, a typed sentinel, and
`rate_limit_shed`, which walks an error's source chain for an
ApplicationClosed / ReadError::Reset / WriteError::Stopped carrying the
code (including through FrameError::Io's io::Error, whose inner stream
error is reachable only via get_ref). Every connect / open_bi /
write_frame / read_frame site in probe.rs and lib.rs routes through it;
plain messages are unchanged.

node_origin treats the sentinel exactly like the handler-level shed: the
(peer, hash) pair is suppressed for REFUSAL_SUPPRESSION_TTL, a new
`decdn_node_upstream_rate_limited_total` counter ticks, and no reputation
outcome is recorded. New PullVerdict::RateLimited folds to
PullMiss::Clean. ADR 013's 0x10 row names the consumer.

A global-full shed still skips the node's close ack-wait and can arrive
as a bare drop; that residue keeps scoring Unreachable.

Closes #1986

Co-Authored-By: Claude Opus 5 <[email protected]>
@github-actions

github-actions Bot commented Sep 11, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 82.69% (was 82.68%, ▲ +0.01%) — 76653/92697 lines

File Coverage Lines Δ
crates/client-pull/src/lib.rs 89.42% 1690/1890 ● 0.00%
crates/client-pull/src/probe.rs 92.68% 152/164 ▲ +0.61%
crates/client-pull/src/rate_limited.rs 94.66% 124/131 new
crates/node/src/metrics.rs 94.66% 886/936 ● 0.00%
crates/node/src/node_origin/mod.rs 92.20% 1028/1115 ▼ 0.72%
History
Commit Total Δ vs base
720dd8f 82.69% ▲ +0.02%
837cff9 (HEAD) 82.69% ▲ +0.01%

APP_ERR_RATE_LIMITED is only sent before any application stream exists
(ADR 013 §Application Error Codes), so route only the open-stage transport
calls — connect, open_bi, the initial request write, and read_stream_response
— through transport_error. The two mid-delivery helpers, write_message
(vouchers) and read_client_message, keep plain error text: typing a shed
there would trust the "0x10 only pre-stream" invariant rather than scope the
recovery to where the limiters can actually fire, and would let a peer dodge
the Unreachable score by resetting a stream 0x10 mid-delivery.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@alpergundogdu
alpergundogdu merged commit 96636ac into main Sep 11, 2026
25 checks passed
@alpergundogdu
alpergundogdu deleted the claude/github-issue-1986-463d78 branch September 11, 2026 09:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

node: connection-level rate-limit rejection (0x10) is unread by the requester and scores the peer Unreachable

2 participants