From 4d9ceef3b3c7ef1368bcb282da18598dae26b2c3 Mon Sep 17 00:00:00 2001 From: Benjamin Pracht Date: Wed, 3 Jul 2024 10:38:13 -0700 Subject: [PATCH] Stop output sdk watchdog on teardown (#287) --- pkg/lksdk_output/lksdk_output.go | 4 ++++ pkg/lksdk_output/watchdog.go | 13 ++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/pkg/lksdk_output/lksdk_output.go b/pkg/lksdk_output/lksdk_output.go index 6448704d..b10f5df8 100644 --- a/pkg/lksdk_output/lksdk_output.go +++ b/pkg/lksdk_output/lksdk_output.go @@ -306,6 +306,10 @@ func (s *LKSDKOutput) closeOutput() { // only close the outputs once s.outputs = nil + if s.watchdog != nil { + s.watchdog.Stop() + } + if s.room != nil { s.room.Disconnect() } diff --git a/pkg/lksdk_output/watchdog.go b/pkg/lksdk_output/watchdog.go index 69f20727..07804d2e 100644 --- a/pkg/lksdk_output/watchdog.go +++ b/pkg/lksdk_output/watchdog.go @@ -27,12 +27,14 @@ type Watchdog struct { expectedTrackCount int boundTrackCount int timer *time.Timer + started bool } func NewWatchdog(onFire func(), deadline time.Duration) *Watchdog { return &Watchdog{ onFire: onFire, deadline: deadline, + started: true, } } @@ -63,9 +65,18 @@ func (w *Watchdog) TrackUnbound() { w.updateTimer() } +func (w *Watchdog) Stop() { + w.trackLock.Lock() + defer w.trackLock.Unlock() + + w.started = false + + w.updateTimer() +} + // Must be called locked func (w *Watchdog) updateTimer() { - timerMustBeActive := w.boundTrackCount < w.expectedTrackCount + timerMustBeActive := w.started && w.boundTrackCount < w.expectedTrackCount if w.timer == nil && timerMustBeActive { w.timer = time.AfterFunc(w.deadline, w.onFire)