Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop output sdk watchdog on teardown #287

Merged
merged 2 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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