Process as many events as possible in update. (#1010)

With removal of subscription, it could happen twice.
When the subscriber actually unusbscribes and the publisher
removing all subscribers. The second unsubscribe was never
removed from the event list and eventually timed out.
So, process events as long as condition is satisfied.
This commit is contained in:
Raja Subramanian
2022-09-15 22:53:44 +05:30
committed by GitHub
parent 60297b24fd
commit 6234e4e725
2 changed files with 26 additions and 32 deletions
+13 -16
View File
@@ -139,23 +139,20 @@ func (p *PublicationMonitor) IsIdle() bool {
} }
func (p *PublicationMonitor) update() { func (p *PublicationMonitor) update() {
var pub *publish for {
if p.desiredPublishes.Len() > 0 { var pub *publish
pub = p.desiredPublishes.PopFront().(*publish) if p.desiredPublishes.Len() > 0 {
} pub = p.desiredPublishes.PopFront().(*publish)
}
if pub == nil { if pub == nil {
return return
} }
switch { if (pub.isStart && p.publishedTrack == nil) || (!pub.isStart && p.publishedTrack != nil) {
case pub.isStart && p.publishedTrack != nil: // put it back as the condition is not satisfied
return p.desiredPublishes.PushFront(pub)
case !pub.isStart && p.publishedTrack == nil: return
return }
default:
// put it back as the condition is not satisfied
p.desiredPublishes.PushFront(pub)
return
} }
} }
+13 -16
View File
@@ -117,23 +117,20 @@ func (s *SubscriptionMonitor) IsIdle() bool {
} }
func (s *SubscriptionMonitor) update() { func (s *SubscriptionMonitor) update() {
var tx *transition for {
if s.desiredTransitions.Len() > 0 { var tx *transition
tx = s.desiredTransitions.PopFront().(*transition) if s.desiredTransitions.Len() > 0 {
} tx = s.desiredTransitions.PopFront().(*transition)
}
if tx == nil { if tx == nil {
return return
} }
switch { if (tx.isSubscribed && s.subscribedTrack == nil) || (!tx.isSubscribed && s.subscribedTrack != nil) {
case tx.isSubscribed && s.subscribedTrack != nil: // put it back as the condition is not satisfied
return s.desiredTransitions.PushFront(tx)
case !tx.isSubscribed && s.subscribedTrack == nil: return
return }
default:
// put it back as the condition is not satisfied
s.desiredTransitions.PushFront(tx)
return
} }
} }