Browse Source

fix: whep deadlock on network issues

pull/3110/head
Jonathan Martin 2 years ago committed by aler9
parent
commit
531e840457
  1. 7
      internal/protocols/webrtc/peer_connection.go
  2. 2
      internal/protocols/webrtc/whip_client.go

7
internal/protocols/webrtc/peer_connection.go

@ -39,6 +39,9 @@ type PeerConnection struct { @@ -39,6 +39,9 @@ type PeerConnection struct {
closed chan struct{}
gatheringDone chan struct{}
incomingTrack chan trackRecvPair
ctx context.Context
ctxCancel context.CancelFunc
}
// Start starts the peer connection.
@ -60,6 +63,8 @@ func (co *PeerConnection) Start() error { @@ -60,6 +63,8 @@ func (co *PeerConnection) Start() error {
co.gatheringDone = make(chan struct{})
co.incomingTrack = make(chan trackRecvPair)
co.ctx, co.ctxCancel = context.WithCancel(context.Background())
if !co.Publish {
_, err = co.wr.AddTransceiverFromKind(webrtc.RTPCodecTypeVideo, webrtc.RtpTransceiverInit{
Direction: webrtc.RTPTransceiverDirectionRecvonly,
@ -119,6 +124,7 @@ func (co *PeerConnection) Start() error { @@ -119,6 +124,7 @@ func (co *PeerConnection) Start() error {
case co.newLocalCandidate <- &v:
case <-co.connected:
case <-co.closed:
case <-co.ctx.Done():
}
} else {
close(co.gatheringDone)
@ -130,6 +136,7 @@ func (co *PeerConnection) Start() error { @@ -130,6 +136,7 @@ func (co *PeerConnection) Start() error {
// Close closes the connection.
func (co *PeerConnection) Close() {
co.ctxCancel()
co.wr.Close() //nolint:errcheck
<-co.closed
}

2
internal/protocols/webrtc/whip_client.go

@ -180,7 +180,7 @@ outer: @@ -180,7 +180,7 @@ outer:
for {
select {
case ca := <-c.pc.NewLocalCandidate():
err := WHIPPatchCandidate(context.Background(), c.HTTPClient, c.URL.String(), offer, res.ETag, ca)
err := WHIPPatchCandidate(ctx, c.HTTPClient, c.URL.String(), offer, res.ETag, ca)
if err != nil {
c.pc.Close()
return nil, err

Loading…
Cancel
Save