ignore abnormal forward delay (#2748)

This commit is contained in:
cnderrauber authored and GitHub committed 2024-05-31 10:23:37 +08:00
1 parent 3ad0a69c86
commit 526d3a017e
1 file changed
+6 -1
+6 -1
View File
@@ -27,13 +27,18 @@ func NewForwardStats(latencyUpdateInterval, reportInterval, latencyWindowLength
}
func (s *ForwardStats) Update(arrival, left time.Time) {
transit := left.Sub(arrival)
// ignore if transit is too large or negative, this could happen if system time is adjusted
if transit < 0 || transit > 5*time.Second {
return
}
leftMs := left.UnixMilli()
lastMs := s.lastLeftMs.Load()
if leftMs < lastMs || !s.lastLeftMs.CompareAndSwap(lastMs, leftMs) {
return
}
transit := left.Sub(arrival)
s.lock.Lock()
defer s.lock.Unlock()
s.latency.Update(time.Duration(arrival.UnixNano()), float64(transit))