Skip to content

fix(node): bound the DHT dial and skip a peer whose dial timed out - #2536

Merged
thiras merged 2 commits into
mainfrom
fix/dht-dead-peer-dial-timeout-2532
Oct 18, 2026
Merged

thiras merged 2 commits into
mainfrom
fix/dht-dead-peer-dial-timeout-2532

Conversation

@thiras

@thiras thiras commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

What

A third of the fleet's DHT lookups waited the full 8 s round because one bonded peer never answers find_value. The on-chain check (comment on #2532) names it: a third-party bond registered 2026-10-13 from 177.2.140.159 (BR), not in our fleet, which we cannot deregister. A bonded-but-dead peer is a permanent condition of an open network, so the fix is node-local.

Two mechanisms, both constants, no config knob, no wire or on-chain change:

  1. A dial budget below the round timeout. dht/client.rs wrapped connect + handshake + exchange in one DHT_CLIENT_TIMEOUT (8 s), level with DEFAULT_ROUND_TIMEOUT (8 s), and the round clock starts after the RPC tasks spawn, so the round timer always fired first. The connect and handshake are now bounded separately at DHT_DIAL_TIMEOUT (2 s) and fail as a bare, typed DialTimeout { peer }. DHT_CLIENT_TIMEOUT stays as the belt over an accepted connection that stalls. A const assert pins DHT_DIAL_TIMEOUT < DEFAULT_ROUND_TIMEOUT.
  2. A per-peer dial-failure cooldown on the routing table. RoutingTable::mark_unreachable(peer, now) records the peer; cooling_peers(now) is the snapshot a lookup takes under the same lock as its seed; LookupState::add_candidate rejects a cooling peer from the seed and from closer_nodes answers alike. A peer a round timeout aborts is marked too. closest() is unchanged, so closer_nodes answers to other nodes and the republish fan-out still name the peer; the skip is this node's own. An insert or refresh of the peer (an inbound request does one) or DIAL_FAILURE_COOLDOWN (5 min) ends it.

Observability: decdn_dht_lookup_dial_timeouts_total (new) and a cooling field on the dht_lookup span. The appendix also gains the decdn_dht_lookup_round_ceiling_total row, which was missing (the exporter emitted it; the ADR did not list it).

Closes #2532

Reviewer notes

  • Read exchange_payload in crates/node/src/dht/client.rs, then run_round / mark_unreachable / LookupState::new in dht/lookup.rs, then the cooling map in dht/routing.rs.
  • DEFAULT_ROUND_TIMEOUT and PULL_THROUGH_OUTER_SLACK are unchanged on purpose: the dial budget is what binds for a dead peer, and moving the round budget would move the pull deadline derivation.
  • The cooldown clears on any insert or refresh of the peer, not only on an inbound request from it. The hourly bucket refresh can therefore re-insert a dead peer from another node's closer_nodes, costing one more 2 s dial per hour at worst. Chosen over a separate "proof of liveness" insert path; the ADR text says "inserts or refreshes" so it is not overstated.
  • Spec-discipline check: both mechanisms have a concrete failure sentence (above), a live consumer (find_providers), sit at constant altitude, and are self-enforced by the node they protect. Nothing on-chain, nothing a peer could exploit beyond being offline.
  • Expected fleet effect after rollout: decdn_dht_lookup_round_timeouts_total falls to ~0; decdn_dht_lookup_dial_timeouts_total reads about one per node per 5 min while the BR bond stays dead; dht_lookup spans stop sitting at 8.00 s.

Verification

  • cargo fmt -- --check
  • CARGO_BUILD_WARNINGS=deny cargo clippy --workspace --all-targets (hook form) and cargo clippy --workspace --all-targets --all-features -- -D warnings
  • cargo nextest run -p decdn-node (full crate), including:
    • find_providers_tolerates_unreachable_peer now asserts the lookup finishes inside the 3 s test round, one dial timeout and zero round timeouts counted, the peer marked, and a second lookup that skips it entirely (< 2 s, counter unchanged).
    • client_fails_an_unanswered_dial_at_the_dial_timeout (new, dht_loopback): a closed loopback peer fails as DialTimeout naming it, between the dial and half the exchange budget.
    • routing/lookup unit tests for mark / is_cooling / sweep / refresh-clears / remove-clears / closest-unchanged / seed-and-response skip / lapsed cooldown.
    • adr_registry_names_are_exported and observability_counters_export_at_zero cover the new counter and the round-ceiling row.
  • CARGO_BUILD_WARNINGS=deny cargo doc --workspace --no-deps --document-private-items
  • make -C adr check-refs
  • contracts/ changed: n/a
  • User-visible change: CHANGELOG.md entry added
  • Design change: ADR 022 § Routing Table and the observability appendix updated
  • PR title uses a type the pr-title check allows, lowercase subject

Follow-up (not here)

  • decdn/devops: the node dashboard has a round-timeouts panel; add decdn_dht_lookup_dial_timeouts_total beside it after the release.

🤖 Generated with Claude Code

…2532)

The registry seeds every bonded peer into every routing table, and a
bond does not say whether the node behind it answers. One such peer on
the testnet resolves an address from the registry mirror, so every
`FIND_VALUE` dial to it sends a handshake that nothing answers. The DHT
client wrapped connect, handshake and exchange in one 8 s timeout, level
with the 8 s round timeout, so every lookup whose α batch held the peer
ran to the round timeout, and nothing recorded which peer it was.

The client now bounds the connect and handshake separately at
`DHT_DIAL_TIMEOUT` (2 s) and fails them as a bare `DialTimeout` naming
the peer. The lookup marks that peer in the routing table
(`RoutingTable::mark_unreachable`), and this node's lookups skip it for
`DIAL_FAILURE_COOLDOWN` (5 min), from the seed and from `closer_nodes`
answers alike. A peer a round timeout aborts is marked the same way. The
peer stays in the table and in the answers this node gives; an insert or
refresh of it, which an inbound request does, ends the skip.

`decdn_dht_lookup_dial_timeouts_total` counts the dials that timed out,
and the `dht_lookup` span records the `cooling` peers skipped. ADR 022
§ Routing Table states the rule; the observability appendix gains the
row, and the one for the round ceiling that was missing.

Closes #2532

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 18, 2026 22:12

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Cooldown filtering can hide healthy seed alternatives, and failed referral-only peers escape cooldown tracking.

2 open issues
What changed in this PR

Reduces DHT lookup delays from offline bonded peers using a shorter dial timeout and node-local cooldowns.

Changes:

  • Adds a typed 2-second dial timeout and 5-minute peer cooldown.
  • Adds timeout metrics, tracing, and regression tests.
  • Documents the behavior without changing wire formats or contracts.
File Description
crates/​node/​tests/​dht_loopback.rs Tests typed dial timeouts.
crates/​node/​tests/​dht_integration.rs Tests timeout accounting and cooldown skipping.
crates/​node/​src/​metrics/​tests.rs Checks exported counters.
crates/​node/​src/​metrics.rs Adds the dial-timeout counter.
crates/​node/​src/​dht/​routing/​tests.rs Tests cooldown lifecycle.
crates/​node/​src/​dht/​routing.rs Tracks peer cooldowns.
crates/​node/​src/​dht/​lookup/​tests.rs Tests cooling-candidate filtering.
crates/​node/​src/​dht/​lookup.rs Marks failed peers and skips cooling candidates.
crates/​node/​src/​dht/​client.rs Bounds dialing separately from exchanges.
CHANGELOG.md Describes the lookup improvement.
adr/​appendix-observability.md Documents lookup counters.
adr/​022-content-discovery.md Specifies local timeout and cooldown behavior.

Review effort: Balanced

Comment thread crates/node/src/dht/lookup.rs Resolved
Comment thread crates/node/src/dht/routing.rs Resolved
@github-code-quality

github-code-quality Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Code coverage overview

Languages: Rust

Rust / code-coverage/cargo-llvm-cov

main 3c4d34f fix/dht-dead-peer-di... 85349e2 +/-
76% 76% 0%
View coverage of the 6 most impacted files.
File main 3c4d34f fix/dht-dead-peer-di... 85349e2 +/-
crates/node/src/dht/lookup.rs 92% 88% -4%
crates/node/src/dht/client.rs 81% 79% -2%
crates/client/src/lib.rs 89% 89% 0%
crates/node/src...s/client/mod.rs 91% 91% 0%
crates/node/src/dht/routing.rs 96% 96% 0%
crates/node/src/dht/publish.rs 78% 80% +2%

ℹ️ Calculations represent line coverage. Results may change as calculations are updated.


Updated October 18, 2026 22:35 UTC

… and mark dead referrals

Review of #2536. The seed took the nearest `4α` peers and then dropped
the cooling ones, so twelve cooling peers nearer the target than a live
peer left the lookup with no seed. `LookupState::seed_from` reads the
table past the seed count by the number of cooling peers and keeps the
nearest peers that are not cooling; `closest()` is unchanged.

`RoutingTable::mark_unreachable` marked only peers in a bucket. A peer a
`closer_nodes` answer named is dialed without entering the table, so a
dead referral lost its mark and the next lookup dialed it again. The
mark no longer needs table membership; the map is bounded by the active
staker set and sweeps lapsed entries on read.

Unit tests cover both shapes, and a two-hop integration test proves the
second lookup skips a dead referral without a second dial.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@thiras
thiras merged commit 8f17157 into main Oct 18, 2026
31 checks passed
@thiras
thiras deleted the fix/dht-dead-peer-dial-timeout-2532 branch October 18, 2026 22:40
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.

dht: a dead bonded peer makes a third of lookups wait the 8 s round timeout

2 participants