File tree Expand file tree Collapse file tree 1 file changed +14
-4
lines changed 
packages/core/pegboard-runner/src Expand file tree Collapse file tree 1 file changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -84,10 +84,20 @@ async fn handle_message(
8484)  -> Result < ( ) >  { 
8585	match  msg { 
8686		protocol:: ToServer :: ToServerPing ( ping)  => { 
87- 			let  rtt = util:: timestamp:: now ( ) 
88- 				. saturating_sub ( ping. ts ) 
89- 				. try_into ( ) 
90- 				. context ( "failed to calculate RTT from ping timestamp" ) ?; 
87+ 			let  now = util:: timestamp:: now ( ) ; 
88+ 			let  rtt = if  ping. ts  <= now { 
89+ 				// Calculate RTT, clamping to u32::MAX if too large 
90+ 				let  rtt_ms = now. saturating_sub ( ping. ts ) ; 
91+ 				rtt_ms. min ( u32:: MAX  as  i64 )  as  u32 
92+ 			}  else  { 
93+ 				// If ping timestamp is in the future (clock skew), default to 0 
94+ 				tracing:: warn!( 
95+ 					ping_ts = ping. ts, 
96+ 					now_ts = now, 
97+ 					"ping timestamp is in the future, possibly due to clock skew" 
98+ 				) ; 
99+ 				0 
100+ 			} ; 
91101
92102			conn. last_rtt . store ( rtt,  Ordering :: Relaxed ) ; 
93103		} 
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments