You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(transport): sample RTT from ping/pong keep-alive cycle
## Problem
`TransportMetrics::record_rtt_sample` was only reachable from
`record_transfer_completed`, which fires on stream-transfer completion.
Connections that exchange only keep-alive / control / small-contract
traffic for hours never complete a stream transfer, so they contributed
zero RTT samples. The dashboard / telemetry RTT statistics
(`min_rtt_us`, `max_rtt_us`, `avg_rtt_us`) under-represented quiet
connections. Same class of undercounting as the per-peer SENT/RECV bug
fixed in #3996.
## Approach
The ping/pong keep-alive cycle already records each Ping's send
timestamp in `pending_pings` (sequence -> nanos). The Pong handler
already removed the matching entry but discarded the timestamp. Capture
it, compute the round-trip against the same `time_source`, and record an
RTT sample. The keep-alive cycle runs on every connection regardless of
stream traffic, so RTT statistics now stay populated for quiet,
long-lived connections.
- `record_rtt_sample` widened from private to `pub(crate)` so the
connection layer can call it (it was already the shared sink for the
stream-completion path).
- The `rtt_us > 0` guard mirrors the existing stream-completion path.
- The write lock on `pending_pings` is released before recording the
sample.
This is observation-only: it does not feed congestion control (the
shadow-RTT system in #4074 remains the path for that).
## Testing
New regression test `pong_records_rtt_sample_from_keepalive_cycle`
drives an encrypted Pong through the real `recv()` path after seeding a
pending ping, and asserts the global RTT sample counter advances and the
ping is consumed. Verified it FAILS without the fix (records zero
samples) and PASSES with it. Full transport lib suite (607 tests) green;
`cargo clippy --locked -- -D warnings` clean.
Closes#4000
[AI-assisted - Claude]
0 commit comments