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
+1 -1
View File
@@ -18,7 +18,7 @@ require (
github.com/jxskiss/base62 v1.1.0 github.com/jxskiss/base62 v1.1.0
github.com/livekit/mageutil v0.0.0-20230125210925-54e8a70427c1 github.com/livekit/mageutil v0.0.0-20230125210925-54e8a70427c1
github.com/livekit/mediatransportutil v0.0.0-20230130133657-96cfb115473a github.com/livekit/mediatransportutil v0.0.0-20230130133657-96cfb115473a
github.com/livekit/protocol v1.3.3-0.20230131012249-9987dca3a3e7 github.com/livekit/protocol v1.3.3-0.20230202034647-c71216774a62
github.com/livekit/psrpc v0.2.5 github.com/livekit/psrpc v0.2.5
github.com/livekit/rtcscore-go v0.0.0-20220815072451-20ee10ae1995 github.com/livekit/rtcscore-go v0.0.0-20220815072451-20ee10ae1995
github.com/mackerelio/go-osstat v0.2.3 github.com/mackerelio/go-osstat v0.2.3
+2 -2
View File
@@ -234,8 +234,8 @@ github.com/livekit/mageutil v0.0.0-20230125210925-54e8a70427c1 h1:jm09419p0lqTkD
github.com/livekit/mageutil v0.0.0-20230125210925-54e8a70427c1/go.mod h1:Rs3MhFwutWhGwmY1VQsygw28z5bWcnEYmS1OG9OxjOQ= github.com/livekit/mageutil v0.0.0-20230125210925-54e8a70427c1/go.mod h1:Rs3MhFwutWhGwmY1VQsygw28z5bWcnEYmS1OG9OxjOQ=
github.com/livekit/mediatransportutil v0.0.0-20230130133657-96cfb115473a h1:5UkGQpskXp7HcBmyrCwWtO7ygDWbqtjN09Yva4l/nyE= github.com/livekit/mediatransportutil v0.0.0-20230130133657-96cfb115473a h1:5UkGQpskXp7HcBmyrCwWtO7ygDWbqtjN09Yva4l/nyE=
github.com/livekit/mediatransportutil v0.0.0-20230130133657-96cfb115473a/go.mod h1:1Dlx20JPoIKGP45eo+yuj0HjeE25zmyeX/EWHiPCjFw= github.com/livekit/mediatransportutil v0.0.0-20230130133657-96cfb115473a/go.mod h1:1Dlx20JPoIKGP45eo+yuj0HjeE25zmyeX/EWHiPCjFw=
github.com/livekit/protocol v1.3.3-0.20230131012249-9987dca3a3e7 h1:PSSiAMb0XmBrhA8xZzpnf9q99Cl64RmCbL7KzmOMb9s= github.com/livekit/protocol v1.3.3-0.20230202034647-c71216774a62 h1:wLkf7jiWtA0q+3y192KEkWIdKUrh+cXz/pBwVMZBwq4=
github.com/livekit/protocol v1.3.3-0.20230131012249-9987dca3a3e7/go.mod h1:gwCG03nKlHlC9hTjL4pXQpn783ALhmbyhq65UZxqbb8= github.com/livekit/protocol v1.3.3-0.20230202034647-c71216774a62/go.mod h1:gwCG03nKlHlC9hTjL4pXQpn783ALhmbyhq65UZxqbb8=
github.com/livekit/psrpc v0.2.5 h1:+EZS78MGdBZxzCUwinDQ6pOeqPDURisrGtfyyqwUDSI= github.com/livekit/psrpc v0.2.5 h1:+EZS78MGdBZxzCUwinDQ6pOeqPDURisrGtfyyqwUDSI=
github.com/livekit/psrpc v0.2.5/go.mod h1:DyphtRRWvcIuCaldYg9VGpwGhu/HiKmNcysgpN6xKrM= github.com/livekit/psrpc v0.2.5/go.mod h1:DyphtRRWvcIuCaldYg9VGpwGhu/HiKmNcysgpN6xKrM=
github.com/livekit/rtcscore-go v0.0.0-20220815072451-20ee10ae1995 h1:vOaY2qvfLihDyeZtnGGN1Law9wRrw8BMGCr1TygTvMw= github.com/livekit/rtcscore-go v0.0.0-20220815072451-20ee10ae1995 h1:vOaY2qvfLihDyeZtnGGN1Law9wRrw8BMGCr1TygTvMw=
+12 -11
View File
@@ -35,8 +35,8 @@ import (
var ( var (
reconcileInterval = 3 * time.Second reconcileInterval = 3 * time.Second
// amount of time to give up if a track or publisher isn't found // 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 // ensuring this is longer than iceFailedTimeout so we are certain the participant won't return
notFoundTimeout = 20 * time.Second notFoundTimeout = iceFailedTimeout
// amount of time to try otherwise before flagging subscription as failed // amount of time to try otherwise before flagging subscription as failed
subscriptionTimeout = 20 * time.Second subscriptionTimeout = 20 * time.Second
) )
@@ -381,7 +381,6 @@ func (m *SubscriptionManager) reconcileWorker() {
func (m *SubscriptionManager) subscribe(s *trackSubscription) error { func (m *SubscriptionManager) subscribe(s *trackSubscription) error {
s.logger.Debugw("executing subscribe") s.logger.Debugw("executing subscribe")
s.startAttempt()
if !m.params.Participant.CanSubscribe() { if !m.params.Participant.CanSubscribe() {
return ErrNoSubscribePermission return ErrNoSubscribePermission
@@ -602,6 +601,14 @@ func (s *trackSubscription) getPublisherIdentity() livekit.ParticipantIdentity {
func (s *trackSubscription) setDesired(desired bool) bool { func (s *trackSubscription) setDesired(desired bool) bool {
s.lock.Lock() s.lock.Lock()
defer s.lock.Unlock() 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 { if s.desired == desired {
return false return false
} }
@@ -611,8 +618,9 @@ func (s *trackSubscription) setDesired(desired bool) bool {
s.changeNotifier.RemoveObserver(string(s.subscriberID)) s.changeNotifier.RemoveObserver(string(s.subscriberID))
s.changeNotifier = nil s.changeNotifier = nil
} }
if desired { if desired {
// reset attempt // reset attempts
s.numAttempts.Store(0) s.numAttempts.Store(0)
} }
return true return true
@@ -704,13 +712,6 @@ func (s *trackSubscription) isBound() bool {
return s.bound 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) { func (s *trackSubscription) recordAttempt(success bool) {
if !success { if !success {
s.numAttempts.Add(1) s.numAttempts.Add(1)