mirror of
https://github.com/netbirdio/ice.git
synced 2026-05-22 17:10:58 -07:00
Fix turn client routine leak on close
Clean-up turn connection if task run failed.
This commit is contained in:
@@ -415,11 +415,14 @@ func (a *Agent) gatherCandidatesRelay(ctx context.Context, urls []*URL) {
|
||||
return locConn.Close()
|
||||
},
|
||||
}
|
||||
candidate, err := NewCandidateRelay(&relayConfig)
|
||||
if err != nil {
|
||||
relayConnClose := func() {
|
||||
if relayConErr := relayConn.Close(); relayConErr != nil {
|
||||
a.log.Warnf("Failed to close relay %v", relayConErr)
|
||||
}
|
||||
}
|
||||
candidate, err := NewCandidateRelay(&relayConfig)
|
||||
if err != nil {
|
||||
relayConnClose()
|
||||
|
||||
client.Close()
|
||||
closeConnAndLog(locConn, a.log, fmt.Sprintf("Failed to create relay candidate: %s %s: %v\n", network, raddr.String(), err))
|
||||
@@ -427,6 +430,8 @@ func (a *Agent) gatherCandidatesRelay(ctx context.Context, urls []*URL) {
|
||||
}
|
||||
|
||||
if err := a.addCandidate(ctx, candidate, relayConn); err != nil {
|
||||
relayConnClose()
|
||||
|
||||
if closeErr := candidate.close(); closeErr != nil {
|
||||
a.log.Warnf("Failed to close candidate: %v", closeErr)
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
package ice
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net"
|
||||
"testing"
|
||||
@@ -412,3 +413,47 @@ func TestVNetGatherWithInterfaceFilter(t *testing.T) {
|
||||
assert.NoError(t, a.Close())
|
||||
})
|
||||
}
|
||||
|
||||
func TestVNetGather_TURNConnectionLeak(t *testing.T) {
|
||||
report := test.CheckRoutines(t)
|
||||
defer report()
|
||||
|
||||
turnServerURL := &URL{
|
||||
Scheme: SchemeTypeTURN,
|
||||
Host: vnetSTUNServerIP,
|
||||
Port: vnetSTUNServerPort,
|
||||
Username: "user",
|
||||
Password: "pass",
|
||||
Proto: ProtoTypeUDP,
|
||||
}
|
||||
|
||||
// buildVNet with a Symmetric NATs for both LANs
|
||||
natType := &vnet.NATType{
|
||||
MappingBehavior: vnet.EndpointAddrPortDependent,
|
||||
FilteringBehavior: vnet.EndpointAddrPortDependent,
|
||||
}
|
||||
v, err := buildVNet(natType, natType)
|
||||
|
||||
if !assert.NoError(t, err, "should succeed") {
|
||||
return
|
||||
}
|
||||
defer v.close()
|
||||
|
||||
cfg0 := &AgentConfig{
|
||||
Urls: []*URL{
|
||||
turnServerURL,
|
||||
},
|
||||
NetworkTypes: supportedNetworkTypes,
|
||||
MulticastDNSMode: MulticastDNSModeDisabled,
|
||||
NAT1To1IPs: []string{vnetGlobalIPA},
|
||||
Net: v.net0,
|
||||
}
|
||||
aAgent, err := NewAgent(cfg0)
|
||||
if !assert.NoError(t, err, "should succeed") {
|
||||
return
|
||||
}
|
||||
|
||||
aAgent.gatherCandidatesRelay(context.Background(), []*URL{turnServerURL})
|
||||
// Assert relay conn leak on close.
|
||||
assert.NoError(t, aAgent.Close())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user