diff --git a/icegatherer.go b/icegatherer.go index 4265c5daa34..569379f9911 100644 --- a/icegatherer.go +++ b/icegatherer.go @@ -7,6 +7,7 @@ package webrtc import ( + "errors" "fmt" "sync" "sync/atomic" @@ -192,7 +193,7 @@ func (g *ICEGatherer) Close() error { if g.agent == nil { return nil - } else if err := g.agent.Close(); err != nil { + } else if err := g.agent.Close(); err != nil && !errors.Is(err, ice.ErrClosed) { return err } diff --git a/icetransport.go b/icetransport.go index 469aafbd43f..26a28541993 100644 --- a/icetransport.go +++ b/icetransport.go @@ -8,6 +8,7 @@ package webrtc import ( "context" + "errors" "fmt" "sync" "sync/atomic" @@ -197,9 +198,13 @@ func (t *ICETransport) Stop() error { } if t.mux != nil { - return t.mux.Close() + if err := t.mux.Close(); err != nil && !errors.Is(err, ice.ErrClosed) { + return err + } } else if t.gatherer != nil { - return t.gatherer.Close() + if err := t.gatherer.Close(); err != nil && !errors.Is(err, ice.ErrClosed) { + return err + } } return nil } diff --git a/peerconnection.go b/peerconnection.go index c6af120097e..bc71deddcc3 100644 --- a/peerconnection.go +++ b/peerconnection.go @@ -2083,7 +2083,12 @@ func (pc *PeerConnection) Close() error { // https://www.w3.org/TR/webrtc/#dom-rtcpeerconnection-close (step #7) closeErrs = append(closeErrs, pc.dtlsTransport.Stop()) - // https://www.w3.org/TR/webrtc/#dom-rtcpeerconnection-close (step #8, #9, #10) + // https://www.w3.org/TR/webrtc/#dom-rtcpeerconnection-close (step #8) + if pc.iceGatherer != nil { + closeErrs = append(closeErrs, pc.iceGatherer.Close()) + } + + // https://www.w3.org/TR/webrtc/#dom-rtcpeerconnection-close (step #9, #10) if pc.iceTransport != nil { closeErrs = append(closeErrs, pc.iceTransport.Stop()) }