Skip to content

Commit

Permalink
Stop output sdk watchdog on teardown (#287)
Browse files Browse the repository at this point in the history
  • Loading branch information
biglittlebigben authored Jul 3, 2024
1 parent ad64539 commit 4d9ceef
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 4 additions & 0 deletions pkg/lksdk_output/lksdk_output.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
13 changes: 12 additions & 1 deletion pkg/lksdk_output/watchdog.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 4d9ceef

Please sign in to comment.