pion / interceptor

Pluggable RTP/RTCP processors for building real time communication

Home Page:https://pion.ly/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Race Condition on a NACK request

opened this issue · comments

Your environment.

  • Version: interceptor v0.0.10 and webrtc v3.0.12
  • Browser: Chrome version 88.0.4324.192 (Official Build) (x86_64)

What did you do?

A race condition occurs when the interceptor tries to resend a packet on a NACK request.

==================
WARNING: DATA RACE
Read at 0x00c00047ba3a by goroutine 61:
  github.com/pion/interceptor/pkg/nack.(*sendBuffer).get()
      /home/ec2-user/go/pkg/mod/github.com/pion/interceptor@v0.0.10/pkg/nack/send_buffer.go:64 +0x8b
  github.com/pion/interceptor/pkg/nack.(*ResponderInterceptor).resendPackets.func1()
      /home/ec2-user/go/pkg/mod/github.com/pion/interceptor@v0.0.10/pkg/nack/responder_interceptor.go:110 +0x59
  github.com/pion/rtcp.(*NackPair).Range()
      /home/ec2-user/go/pkg/mod/github.com/pion/rtcp@v1.2.6/transport_layer_nack.go:64 +0x54
  github.com/pion/interceptor/pkg/nack.(*ResponderInterceptor).resendPackets()
      /home/ec2-user/go/pkg/mod/github.com/pion/interceptor@v0.0.10/pkg/nack/responder_interceptor.go:109 +0x158

Previous write at 0x00c00047ba3a by goroutine 65:
  github.com/pion/interceptor/pkg/nack.(*sendBuffer).add()
      /home/ec2-user/go/pkg/mod/github.com/pion/interceptor@v0.0.10/pkg/nack/send_buffer.go:60 +0x238
  github.com/pion/interceptor/pkg/nack.(*ResponderInterceptor).BindLocalStream.func1()
      /home/ec2-user/go/pkg/mod/github.com/pion/interceptor@v0.0.10/pkg/nack/responder_interceptor.go:88 +0x1b0
  github.com/pion/interceptor.RTPWriterFunc.Write()
      /home/ec2-user/go/pkg/mod/github.com/pion/interceptor@v0.0.10/interceptor.go:82 +0x72
  github.com/pion/webrtc/v3.(*interceptorToTrackLocalWriter).WriteRTP()
      /home/ec2-user/go/pkg/mod/github.com/pion/webrtc/v3@v3.0.12/interceptor.go:69 +0xf5
  github.com/pion/webrtc/v3.(*TrackLocalStaticRTP).writeRTP()
      /home/ec2-user/go/pkg/mod/github.com/pion/webrtc/v3@v3.0.12/track_local_static.go:139 +0x262
  github.com/pion/webrtc/v3.(*TrackLocalStaticRTP).WriteRTP()
      /home/ec2-user/go/pkg/mod/github.com/pion/webrtc/v3@v3.0.12/track_local_static.go:126 +0x168
  main.(*publisher).addListeners.func3()
      /home/ec2-user/publisher.go:129 +0x3fe

Goroutine 61 (running) created at:
  github.com/pion/interceptor/pkg/nack.(*ResponderInterceptor).BindRTCPReader.func1()
      /home/ec2-user/go/pkg/mod/github.com/pion/interceptor@v0.0.10/pkg/nack/responder_interceptor.go:67 +0x195
  github.com/pion/interceptor.RTCPReaderFunc.Read()
      /home/ec2-user/go/pkg/mod/github.com/pion/interceptor@v0.0.10/interceptor.go:97 +0x68
  github.com/pion/webrtc/v3.(*RTPSender).Read()
      /home/ec2-user/go/pkg/mod/github.com/pion/webrtc/v3@v3.0.12/rtpsender.go:215 +0x21c
  github.com/pion/webrtc/v3.(*RTPSender).ReadRTCP()
      /home/ec2-user/go/pkg/mod/github.com/pion/webrtc/v3@v3.0.12/rtpsender.go:224 +0x85
  main.(*subscriber).listenForRtcpPackets()
      /home/ec2-user/subscriber.go:88 +0xdd

Goroutine 65 (running) created at:
  github.com/pion/webrtc/v3.(*PeerConnection).onTrack()
      /home/ec2-user/go/pkg/mod/github.com/pion/webrtc/v3@v3.0.12/peerconnection.go:451 +0x164
  github.com/pion/webrtc/v3.(*PeerConnection).startReceiver.func1()
      /home/ec2-user/go/pkg/mod/github.com/pion/webrtc/v3@v3.0.12/peerconnection.go:1196 +0x5e4
==================
==================
WARNING: DATA RACE
Read at 0x00c0000d5390 by goroutine 60:
  github.com/pion/interceptor/pkg/nack.(*ResponderInterceptor).resendPackets.func1()
      /home/ec2-user/go/pkg/mod/github.com/pion/interceptor@v0.0.10/pkg/nack/responder_interceptor.go:111 +0x126
  github.com/pion/rtcp.(*NackPair).Range()
      /home/ec2-user/go/pkg/mod/github.com/pion/rtcp@v1.2.6/transport_layer_nack.go:64 +0x54
  github.com/pion/interceptor/pkg/nack.(*ResponderInterceptor).resendPackets()
      /home/ec2-user/go/pkg/mod/github.com/pion/interceptor@v0.0.10/pkg/nack/responder_interceptor.go:109 +0x158

Previous write at 0x00c0000d5390 by goroutine 65:
  github.com/pion/interceptor/pkg/nack.(*ResponderInterceptor).BindLocalStream.func1()
      /home/ec2-user/go/pkg/mod/github.com/pion/interceptor@v0.0.10/pkg/nack/responder_interceptor.go:88 +0x96
  github.com/pion/interceptor.RTPWriterFunc.Write()
      /home/ec2-user/go/pkg/mod/github.com/pion/interceptor@v0.0.10/interceptor.go:82 +0x72
  github.com/pion/webrtc/v3.(*interceptorToTrackLocalWriter).WriteRTP()
      /home/ec2-user/go/pkg/mod/github.com/pion/webrtc/v3@v3.0.12/interceptor.go:69 +0xf5
  github.com/pion/webrtc/v3.(*TrackLocalStaticRTP).writeRTP()
      /home/ec2-user/go/pkg/mod/github.com/pion/webrtc/v3@v3.0.12/track_local_static.go:139 +0x262
  github.com/pion/webrtc/v3.(*TrackLocalStaticRTP).WriteRTP()
      /home/ec2-user/go/pkg/mod/github.com/pion/webrtc/v3@v3.0.12/track_local_static.go:126 +0x168
  main.(*publisher).addListeners.func3()
      /home/ec2-user/publisher.go:129 +0x3fe

Goroutine 60 (running) created at:
  github.com/pion/interceptor/pkg/nack.(*ResponderInterceptor).BindRTCPReader.func1()
      /home/ec2-user/go/pkg/mod/github.com/pion/interceptor@v0.0.10/pkg/nack/responder_interceptor.go:67 +0x195
  github.com/pion/interceptor.RTCPReaderFunc.Read()
      /home/ec2-user/go/pkg/mod/github.com/pion/interceptor@v0.0.10/interceptor.go:97 +0x68
  github.com/pion/webrtc/v3.(*RTPSender).Read()
      /home/ec2-user/go/pkg/mod/github.com/pion/webrtc/v3@v3.0.12/rtpsender.go:215 +0x21c
  github.com/pion/webrtc/v3.(*RTPSender).ReadRTCP()
      /home/ec2-user/go/pkg/mod/github.com/pion/webrtc/v3@v3.0.12/rtpsender.go:224 +0x85
  main.(*subscriber).listenForRtcpPackets()
      /home/ec2-user/subscriber.go:88 +0xdd

Goroutine 65 (running) created at:
  github.com/pion/webrtc/v3.(*PeerConnection).onTrack()
      /home/ec2-user/go/pkg/mod/github.com/pion/webrtc/v3@v3.0.12/peerconnection.go:451 +0x164
  github.com/pion/webrtc/v3.(*PeerConnection).startReceiver.func1()
      /home/ec2-user/go/pkg/mod/github.com/pion/webrtc/v3@v3.0.12/peerconnection.go:1196 +0x5e4
==================

That's no good :(

Would you be interested in contributing a test? Maybe one interceptor and do 5 streams, and do like 25% loss and send 1,000 packets. We can fix this easily, but just want to make sure it doesn't regress.