From 246639c5feddee3e14a339bac472aba111e52cfa Mon Sep 17 00:00:00 2001 From: Yeongbin Jeong <113571767+oyobbeb@users.noreply.github.com> Date: Fri, 20 Nov 2026 17:39:12 +0900 Subject: [PATCH] sfu: measure probe timing against mono.Now() (#5247) The probe controller, the probe packet group and the probe cluster store mono.Now() timestamps, but measure the time since them with time.Since. Since livekit/protocol#1439, mono.Now() has no monotonic reading, so time.Since takes the difference from the wall clock. After the wall clock steps, for example on an NTP correction, the settle wait and the probe pacing are off by the step for the rest of the process's life. Use mono.Now().Sub instead. --- pkg/sfu/bwe/remotebwe/probe_controller.go | 2 +- pkg/sfu/bwe/sendsidebwe/probe_packet_group.go | 2 +- pkg/sfu/ccutils/prober.go | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/sfu/bwe/remotebwe/probe_controller.go b/pkg/sfu/bwe/remotebwe/probe_controller.go index 1efa3f655..cd96d38d2 100644 --- a/pkg/sfu/bwe/remotebwe/probe_controller.go +++ b/pkg/sfu/bwe/remotebwe/probe_controller.go @@ -164,7 +164,7 @@ func (p *probeController) MaybeFinalizeProbe() (ccutils.ProbeClusterInfo, bool) if settleWait > p.params.Config.SettleWaitMax { settleWait = p.params.Config.SettleWaitMax } - if time.Since(p.stateSwitchedAt) < settleWait { + if mono.Now().Sub(p.stateSwitchedAt) < settleWait { return ccutils.ProbeClusterInfoInvalid, false } diff --git a/pkg/sfu/bwe/sendsidebwe/probe_packet_group.go b/pkg/sfu/bwe/sendsidebwe/probe_packet_group.go index 68a1b0c79..0cf41c2b3 100644 --- a/pkg/sfu/bwe/sendsidebwe/probe_packet_group.go +++ b/pkg/sfu/bwe/sendsidebwe/probe_packet_group.go @@ -107,7 +107,7 @@ func (p *probePacketGroup) MaybeFinalizeProbe(maxSequenceNumber uint64, rtt floa if settleWait > p.params.Config.SettleWaitMax { settleWait = p.params.Config.SettleWaitMax } - if time.Since(p.doneAt) < settleWait { + if mono.Now().Sub(p.doneAt) < settleWait { return ccutils.ProbeClusterInfoInvalid, false } diff --git a/pkg/sfu/ccutils/prober.go b/pkg/sfu/ccutils/prober.go index 577042ad3..26abe9fff 100644 --- a/pkg/sfu/ccutils/prober.go +++ b/pkg/sfu/ccutils/prober.go @@ -555,7 +555,7 @@ func (c *Cluster) Process() time.Duration { c.startTime = mono.Now() bytesToSend = cBytesPerProbe } else { - sinceStart := time.Since(c.startTime) + sinceStart := mono.Now().Sub(c.startTime) if sinceStart > c.buckets[c.bucketIdx].expectedElapsedDuration { c.bucketIdx++ overflow := false @@ -587,7 +587,7 @@ func (c *Cluster) MarshalLogObject(e zapcore.ObjectEncoder) error { e.AddInt("bucketIdx", c.bucketIdx) e.AddInt("probeBytesSent", c.probeBytesSent) e.AddTime("startTime", c.startTime) - e.AddDuration("elapsed", time.Since(c.startTime)) + e.AddDuration("elapsed", mono.Now().Sub(c.startTime)) e.AddBool("isComplete", c.isComplete) } return nil