diff --git a/peerconnection.go b/peerconnection.go index 7501b4f4486..3b40dafecb6 100644 --- a/peerconnection.go +++ b/peerconnection.go @@ -2113,7 +2113,6 @@ func (pc *PeerConnection) close(shouldGracefullyClose bool) error { } if shouldGracefullyClose && !alreadyGracefullyClosed { defer close(pc.isGracefulClosedDone) - pc.ops.GracefulClose() } // https://www.w3.org/TR/webrtc/#dom-rtcpeerconnection-close (step #3) @@ -2170,6 +2169,8 @@ func (pc *PeerConnection) close(shouldGracefullyClose bool) error { pc.updateConnectionState(pc.ICEConnectionState(), pc.dtlsTransport.State()) if shouldGracefullyClose { + pc.ops.GracefulClose() + // note that it isn't canon to stop gracefully pc.sctpTransport.lock.Lock() for _, d := range pc.sctpTransport.dataChannels {