Skip to content

Commit

Permalink
Fix deadlock in senders closing (#211)
Browse files Browse the repository at this point in the history
  • Loading branch information
OrlandoCo authored Oct 5, 2020
1 parent 5a047f5 commit 28bb637
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions pkg/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ func (w *WebRTCReceiver) SpatialLayer() uint8 {

//closeSenders Close all senders from Receiver
func (w *WebRTCReceiver) closeSenders() {
w.Lock()
defer w.Unlock()
w.RLock()
defer w.RUnlock()
for _, sender := range w.senders {
sender.Close()
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,6 @@ func (s *WebRTCSender) Close() {

func (s *WebRTCSender) close() {
s.cancel()
// Remove sender from receiver
if recv := s.router.GetReceiver(0); recv != nil {
recv.DeleteSender(s.id)
}
if s.onCloseHandler != nil {
s.onCloseHandler()
}
Expand All @@ -118,6 +114,10 @@ func (s *WebRTCSender) receiveRTCP() {
for {
pkts, err := s.sender.ReadRTCP()
if err == io.ErrClosedPipe || s.ctx.Err() != nil {
// Remove sender from receiver
if recv := s.router.GetReceiver(0); recv != nil {
recv.DeleteSender(s.id)
}
s.Close()
return
}
Expand Down

0 comments on commit 28bb637

Please sign in to comment.