Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions gather.go
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,17 @@
return
}

allocDoneCh := make(chan struct{})
go func() {
select {
case <-ctx.Done():
client.Close()
case <-allocDoneCh:

Check warning on line 844 in gather.go

View check run for this annotation

Codecov / codecov/patch

gather.go#L839-L844

Added lines #L839 - L844 were not covered by tests
}
}()

relayConn, err := client.Allocate()
close(allocDoneCh)

Check warning on line 849 in gather.go

View check run for this annotation

Codecov / codecov/patch

gather.go#L849

Added line #L849 was not covered by tests
if err != nil {
client.Close()
closeConnAndLog(locConn, a.log, "failed to allocate on TURN client %s %s", turnServerAddr, err)
Expand Down
48 changes: 48 additions & 0 deletions gather_vnet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"fmt"
"net"
"testing"
"time"

"github.com/pion/logging"
"github.com/pion/stun/v3"
Expand Down Expand Up @@ -435,3 +436,50 @@ func TestVNetGather_TURNConnectionLeak(t *testing.T) {

aAgent.gatherCandidatesRelay(context.Background(), []*stun.URI{turnServerURL})
}

func TestVNetGather_TURNAllocationAbort(t *testing.T) {
defer test.CheckRoutines(t)()

// configure unreachable TURN server
turnServerURL := &stun.URI{
Scheme: stun.SchemeTypeTURN,
Host: vnetSTUNServerIP,
Port: vnetSTUNServerPort,
Username: "user",
Password: "pass",
Proto: stun.ProtoTypeUDP,
}

loggerFactory := logging.NewDefaultLoggerFactory()
router, err := vnet.NewRouter(&vnet.RouterConfig{
CIDR: "10.0.0.0/24",
LoggerFactory: loggerFactory,
})
require.NoError(t, err)

nw, err := vnet.NewNet(&vnet.NetConfig{})
require.NoError(t, err)
require.NoError(t, router.AddNet(nw))

cfg0 := &AgentConfig{
Urls: []*stun.URI{
turnServerURL,
},
NetworkTypes: supportedNetworkTypes(),
MulticastDNSMode: MulticastDNSModeDisabled,
Net: nw,
}
aAgent, err := NewAgent(cfg0)
require.NoError(t, err, "should succeed")
defer func() {
require.NoError(t, aAgent.Close())
}()

// if not canceled, gatherCandidatesRelay() will block for ~7.8s
defer test.TimeOut(time.Second * 1).Stop()

ctx, cancelFunc := context.WithTimeout(context.Background(), 500*time.Millisecond)
defer cancelFunc()

aAgent.gatherCandidatesRelay(ctx, []*stun.URI{turnServerURL})
}
Loading