fix: the KCP io throttle reset itself every cycle, so it never throttled

The send and recv arms shared one counter, and an ICMP error on a connected
socket is reported once and then cleared — so the steady state is an
alternation: the send succeeds and clears the counter, the next recv reports
the error and finds the counter at 1, and logs. Every error still wrote a
line, at the ~100/s the previous commit set out to stop, while the
persistent-failure and recovery branches were unreachable.

Use one LogThrottle per direction instead of a hand-rolled counter. That
removes the shared state the bug lived in, drops a third throttling mechanism
in favour of the one already added, and leaves the surrounding `if let Err`
untouched rather than reshaping it into a match.

Also fix test_udp_uat's socket-error arm, the untreated twin of the punch_udp
site: it had no backoff at all, so a persistent error re-armed recv
immediately and spun the loop at CPU speed, one warn line per iteration.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ExUfAkYbq8UC9pQCiLy8TQ
This commit is contained in:
rustdesk
2026-08-06 14:21:40 +08:00
parent d76b98f7c0
commit 70a124696d
4 changed files with 27 additions and 43 deletions

View File

@@ -332,6 +332,7 @@ async fn race_transports_prefer_webrtc<'a, T: 'a>(
use hbb_common::log_throttle::LogThrottle;
const ICE_LOG_INTERVAL: Duration = Duration::from_secs(60);
static REJECTED_ICE_LOG: LogThrottle = LogThrottle::new(ICE_LOG_INTERVAL);
static UDP_UAT_ERR_LOG: LogThrottle = LogThrottle::new(ICE_LOG_INTERVAL);
static UNEXPECTED_ICE_LOG: LogThrottle = LogThrottle::new(ICE_LOG_INTERVAL);
static PENDING_ICE_FULL_LOG: LogThrottle = LogThrottle::new(ICE_LOG_INTERVAL);
@@ -5165,7 +5166,12 @@ async fn test_udp_uat(
}
}
Err(e) => {
log::warn!("UDP NAT test socket error: {}", e);
// Same ICMP-driven errors as punch_udp sees. Without a pause this arm
// re-arms recv immediately and spins the loop at CPU speed.
if let Some(n) = UDP_UAT_ERR_LOG.due() {
log::warn!("UDP NAT test socket error x{n}, last: {e}");
}
hbb_common::sleep(0.01).await;
}
}
}