Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions packages/core/pegboard-runner/src/client_to_pubsub_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Loading