From c2ee30eac0d6adeb247720730c280f87ee37906d Mon Sep 17 00:00:00 2001 From: Paul Wells Date: Tue, 23 Sep 2025 14:07:50 -0700 Subject: [PATCH 1/2] handle session timer skips >1 min --- observability/sessiontimer.go | 5 +++-- observability/sessiontimer_test.go | 32 ++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 observability/sessiontimer_test.go diff --git a/observability/sessiontimer.go b/observability/sessiontimer.go index c10781886..77b38f1c0 100644 --- a/observability/sessiontimer.go +++ b/observability/sessiontimer.go @@ -19,8 +19,9 @@ func (h *SessionTimer) Advance(now time.Time) (millis, mins int64) { h.lastMilli = ts } if ts > h.lastMin { - mins = 1 - h.lastMin += 60000 + n := (ts - h.lastMin + 59999) / 60000 + mins += n + h.lastMin += n * 60000 } return } diff --git a/observability/sessiontimer_test.go b/observability/sessiontimer_test.go new file mode 100644 index 000000000..26ea0e772 --- /dev/null +++ b/observability/sessiontimer_test.go @@ -0,0 +1,32 @@ +package observability + +import ( + "testing" + "time" + + "github.com/stretchr/testify/require" +) + +func TestSessionTimer(t *testing.T) { + t.Run("advance 100ms", func(t *testing.T) { + ts := time.Now() + st := NewSessionTimer(ts) + + millis, mins := st.Advance(ts.Add(100 * time.Millisecond)) + require.EqualValues(t, 100, millis) + require.EqualValues(t, 1, mins) + + millis, mins = st.Advance(ts.Add(200 * time.Millisecond)) + require.EqualValues(t, 100, millis) + require.EqualValues(t, 0, mins) + }) + + t.Run("advance 2.5m", func(t *testing.T) { + ts := time.Now() + st := NewSessionTimer(ts) + + millis, mins := st.Advance(ts.Add(150 * time.Second)) + require.EqualValues(t, 150000, millis) + require.EqualValues(t, 3, mins) + }) +} From d58f3864367d7f53ba47a32ec800fd870d538ce4 Mon Sep 17 00:00:00 2001 From: Paul Wells Date: Tue, 23 Sep 2025 14:08:37 -0700 Subject: [PATCH 2/2] Create silly-books-attend.md --- .changeset/silly-books-attend.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/silly-books-attend.md diff --git a/.changeset/silly-books-attend.md b/.changeset/silly-books-attend.md new file mode 100644 index 000000000..eb363c62f --- /dev/null +++ b/.changeset/silly-books-attend.md @@ -0,0 +1,5 @@ +--- +"@livekit/protocol": patch +--- + +handle session timer skips >1 min