Skip to content

Commit

Permalink
try to close the mux
Browse files Browse the repository at this point in the history
  • Loading branch information
Yohan Totting committed Apr 8, 2024
1 parent 4a340e5 commit e328524
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 28 deletions.
38 changes: 10 additions & 28 deletions datachannel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,14 +363,23 @@ func TestDataChannel_Close(t *testing.T) {
})

t.Run("Close after PeerConnection With Mux Closed", func(t *testing.T) {
offerPC, answerPC, err := newPairWithMux()
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())
})
}

Expand Down Expand Up @@ -530,30 +539,3 @@ func TestDataChannelParameters(t *testing.T) {
closeReliabilityParamTest(t, offerPC, answerPC, done)
})
}

func newPairWithMux() (*PeerConnection, *PeerConnection, error) {
settingEngine := SettingEngine{}

// Configure our SettingEngine to use our UDPMux. By default a PeerConnection has
// no global state. The API+SettingEngine allows the user to share state between them.
// In this case we are sharing our listening port across many.
// Listen on UDP Port 8443, will be used for all WebRTC traffic
mux, err := ice.NewMultiUDPMuxFromPort(8443)
if err != nil {
panic(err)
}

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
}
19 changes: 19 additions & 0 deletions peerconnection_test.go
Original file line number Diff line number Diff line change
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

0 comments on commit e328524

Please sign in to comment.