Tweaks to subscription reconcile timeout (#1369)

This commit is contained in:
David Zhao
2023-02-01 22:36:14 -08:00
committed by GitHub
parent 8ba6418ab4
commit 40120db993
3 changed files with 15 additions and 14 deletions
+12 -11
View File
@@ -35,8 +35,8 @@ import (
var (
reconcileInterval = 3 * time.Second
// amount of time to give up if a track or publisher isn't found
// giving this a lot of time because during migrations the user could take a lot of time to resume
notFoundTimeout = 20 * time.Second
// ensuring this is longer than iceFailedTimeout so we are certain the participant won't return
notFoundTimeout = iceFailedTimeout
// amount of time to try otherwise before flagging subscription as failed
subscriptionTimeout = 20 * time.Second
)
@@ -381,7 +381,6 @@ func (m *SubscriptionManager) reconcileWorker() {
func (m *SubscriptionManager) subscribe(s *trackSubscription) error {
s.logger.Debugw("executing subscribe")
s.startAttempt()
if !m.params.Participant.CanSubscribe() {
return ErrNoSubscribePermission
@@ -602,6 +601,14 @@ func (s *trackSubscription) getPublisherIdentity() livekit.ParticipantIdentity {
func (s *trackSubscription) setDesired(desired bool) bool {
s.lock.Lock()
defer s.lock.Unlock()
if desired {
// as long as user explicitly set it to desired
// we'll reset the timer so it has sufficient time to reconcile
t := time.Now()
s.subStartedAt.Store(&t)
}
if s.desired == desired {
return false
}
@@ -611,8 +618,9 @@ func (s *trackSubscription) setDesired(desired bool) bool {
s.changeNotifier.RemoveObserver(string(s.subscriberID))
s.changeNotifier = nil
}
if desired {
// reset attempt
// reset attempts
s.numAttempts.Store(0)
}
return true
@@ -704,13 +712,6 @@ func (s *trackSubscription) isBound() bool {
return s.bound
}
func (s *trackSubscription) startAttempt() {
if s.numAttempts.Load() == 0 {
t := time.Now()
s.subStartedAt.Store(&t)
}
}
func (s *trackSubscription) recordAttempt(success bool) {
if !success {
s.numAttempts.Add(1)