Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix goroutine leaks when using datachannel with a multi mux with single port #2739

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 21 additions & 0 deletions datachannel_test.go
Expand Up @@ -10,6 +10,7 @@ import (
"testing"
"time"

"github.com/pion/ice/v3"
"github.com/pion/transport/v3/test"
"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -360,6 +361,26 @@ func TestDataChannel_Close(t *testing.T) {
assert.NoError(t, dc.Close())
closePairNow(t, offerPC, answerPC)
})

t.Run("Close after PeerConnection With Mux Closed", func(t *testing.T) {
mux, err := ice.NewMultiUDPMuxFromPort(8443)
if err != nil {
panic(err)
}

offerPC, answerPC, err := newPairWithMux(mux)
assert.NoError(t, err)

dc, err := offerPC.CreateDataChannel(expectedLabel, nil)
assert.NoError(t, err)

closePairNow(t, offerPC, answerPC)
assert.NoError(t, dc.Close())

// close the mux here just a test, it is confirmed when close the mux the go routine won't be leaks
// but in SFU context, as explain in the issue https://github.com/pion/webrtc/issues/2738 the mux is never closed.
// assert.NoError(t, mux.Close())
})
}

func TestDataChannelParameters(t *testing.T) {
Expand Down
19 changes: 19 additions & 0 deletions peerconnection_test.go
Expand Up @@ -10,6 +10,7 @@ import (
"testing"
"time"

"github.com/pion/ice/v3"
"github.com/pion/sdp/v3"
"github.com/pion/transport/v3/test"
"github.com/pion/webrtc/v4/pkg/rtcerr"
Expand All @@ -32,6 +33,24 @@ func newPair() (pcOffer *PeerConnection, pcAnswer *PeerConnection, err error) {
return pca, pcb, nil
}

func newPairWithMux(mux *ice.MultiUDPMuxDefault) (*PeerConnection, *PeerConnection, error) {
settingEngine := SettingEngine{}

settingEngine.SetICEUDPMux(mux)
api := NewAPI(WithSettingEngine(settingEngine))
pca, err := api.NewPeerConnection(Configuration{})
if err != nil {
return nil, nil, err
}

pcb, err := NewPeerConnection(Configuration{})
if err != nil {
return nil, nil, err
}

return pca, pcb, nil
}

func signalPairWithModification(pcOffer *PeerConnection, pcAnswer *PeerConnection, modificationFunc func(string) string) error {
// Note(albrow): We need to create a data channel in order to trigger ICE
// candidate gathering in the background for the JavaScript/Wasm bindings. If
Expand Down