From 261ad3127b169c7d9d3b1375ead1a76830234686 Mon Sep 17 00:00:00 2001 From: Nathan Flurry Date: Thu, 25 Sep 2025 01:33:55 -0700 Subject: [PATCH] fix(pegboard-runner): handle overflow for ping ts diff --- .../src/client_to_pubsub_task.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/packages/core/pegboard-runner/src/client_to_pubsub_task.rs b/packages/core/pegboard-runner/src/client_to_pubsub_task.rs index 54c7b1e660..f853f01370 100644 --- a/packages/core/pegboard-runner/src/client_to_pubsub_task.rs +++ b/packages/core/pegboard-runner/src/client_to_pubsub_task.rs @@ -84,10 +84,20 @@ async fn handle_message( ) -> Result<()> { match msg { protocol::ToServer::ToServerPing(ping) => { - let rtt = util::timestamp::now() - .saturating_sub(ping.ts) - .try_into() - .context("failed to calculate RTT from ping timestamp")?; + let now = util::timestamp::now(); + let rtt = if ping.ts <= now { + // Calculate RTT, clamping to u32::MAX if too large + let rtt_ms = now.saturating_sub(ping.ts); + rtt_ms.min(u32::MAX as i64) as u32 + } else { + // If ping timestamp is in the future (clock skew), default to 0 + tracing::warn!( + ping_ts = ping.ts, + now_ts = now, + "ping timestamp is in the future, possibly due to clock skew" + ); + 0 + }; conn.last_rtt.store(rtt, Ordering::Relaxed); }