Fixed deadlocks occurring in Receiver writeRTP (#189)
When we RLock during write cycles, the mutex spends the majority of its time staying locked. As new participants join, they have to acquire the WLock before downtracks could be add it. In load test scenarios (25 participants joining together), it's common to see goroutine dump showing MediaTrack.AddSubscriber -> DownTrack.storeDownTrack trying to acquire mutex, and never able to acquire it.
This commit is contained in:
@@ -199,7 +199,7 @@ func (t *MediaTrack) AddSubscriber(sub types.Participant) error {
|
||||
//
|
||||
// AddTrack will create a new transceiver or re-use an unused one
|
||||
// if the attributes match. This prevents SDP from bloating
|
||||
// because of dormant transceivers buidling up.
|
||||
// because of dormant transceivers building up.
|
||||
//
|
||||
sender, err = sub.SubscriberPC().AddTrack(downTrack)
|
||||
if err != nil {
|
||||
|
||||
@@ -472,12 +472,7 @@ func (p *ParticipantImpl) ICERestart() error {
|
||||
|
||||
// AddSubscriber subscribes op to all publishedTracks
|
||||
func (p *ParticipantImpl) AddSubscriber(op types.Participant) (int, error) {
|
||||
p.lock.RLock()
|
||||
tracks := make([]types.PublishedTrack, 0, len(p.publishedTracks))
|
||||
for _, t := range p.publishedTracks {
|
||||
tracks = append(tracks, t)
|
||||
}
|
||||
p.lock.RUnlock()
|
||||
tracks := p.GetPublishedTracks()
|
||||
|
||||
if len(tracks) == 0 {
|
||||
return 0, nil
|
||||
|
||||
Reference in New Issue
Block a user