From ffb5770f77bb7303577d32bcbdc1dea637f47d8c Mon Sep 17 00:00:00 2001 From: Simon Cousineau Date: Fri, 2 Feb 2024 16:59:32 +0000 Subject: [PATCH 1/4] Close peerconnection ice gatherer on close --- peerconnection.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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()) } From 9ae37d276e571c2466e330e47db25248c97fc5dd Mon Sep 17 00:00:00 2001 From: Simon Cousineau Date: Fri, 2 Feb 2024 18:26:08 +0000 Subject: [PATCH 2/4] Check for ErrClosed on ice gatherer close --- icegatherer.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/icegatherer.go b/icegatherer.go index 4265c5daa34..cce3bbe1fa7 100644 --- a/icegatherer.go +++ b/icegatherer.go @@ -192,7 +192,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 && err != ice.ErrClosed { return err } From 372c0a2e7f786c08494bf09266275c9d0f3c4af6 Mon Sep 17 00:00:00 2001 From: Simon Cousineau Date: Fri, 2 Feb 2024 18:28:52 +0000 Subject: [PATCH 3/4] Compare with errors.Is --- icegatherer.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/icegatherer.go b/icegatherer.go index cce3bbe1fa7..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 && err != ice.ErrClosed { + } else if err := g.agent.Close(); err != nil && !errors.Is(err, ice.ErrClosed) { return err } From ec352d56f13b9b424d74638125e2439fbeb945af Mon Sep 17 00:00:00 2001 From: Simon Cousineau Date: Fri, 2 Feb 2024 19:38:01 +0000 Subject: [PATCH 4/4] Check for ErrClosed on ice transport close --- icetransport.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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 }