Add turn client Close support

Fix the goroutine leak.
This commit is contained in:
Aleksandr Razumov
2019-06-07 20:42:39 -07:00
committed by Sean DuBois
parent f335ea3cc2
commit 116ba6b111
5 changed files with 18 additions and 12 deletions
+8 -2
View File
@@ -2,6 +2,7 @@ package ice
import (
"errors"
"io"
"net"
"github.com/pion/turnc"
@@ -12,6 +13,7 @@ type CandidateRelay struct {
candidateBase
allocation *turnc.Allocation
client io.Closer
permissions map[string]*turnc.Permission
}
@@ -38,8 +40,9 @@ func NewCandidateRelay(network string, ip net.IP, port int, component uint16, re
}, nil
}
func (c *CandidateRelay) setAllocation(a *turnc.Allocation) {
func (c *CandidateRelay) setAllocation(client io.Closer, a *turnc.Allocation) {
c.allocation = a
c.client = client
}
func (c *CandidateRelay) start(a *Agent, conn net.PacketConn) {
@@ -54,7 +57,10 @@ func (c *CandidateRelay) close() error {
return err
}
}
return nil
if c.client == nil {
return nil
}
return c.client.Close()
}
func (c *CandidateRelay) addPermission(dst Candidate) error {
+1 -1
View File
@@ -307,7 +307,7 @@ func (a *Agent) gatherCandidatesRelay(urls []*URL) error {
a.log.Warnf("Failed to create server reflexive candidate: %s %s %d: %v\n", network, ip, port, err)
continue
}
candidate.setAllocation(allocation)
candidate.setAllocation(client, allocation)
a.addCandidate(candidate)
candidate.start(a, nil)
+2 -2
View File
@@ -6,7 +6,7 @@ require (
github.com/pion/logging v0.2.1
github.com/pion/stun v0.3.1
github.com/pion/transport v0.7.0
github.com/pion/turn v1.1.3
github.com/pion/turnc v0.0.5
github.com/pion/turn v1.1.4
github.com/pion/turnc v0.0.6
github.com/stretchr/testify v1.3.0
)
+6 -6
View File
@@ -1,8 +1,8 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gortc/turn v0.7.1/go.mod h1:3FZ+LvCZKCKu6YYgwuYPqEi3FqCtdjfSFnFqVQNwfjk=
github.com/gortc/turn v0.7.2 h1:9h0c1CG36LTYgQD54mHxETiNBxg3dNvLOCT85uhtYj4=
github.com/gortc/turn v0.7.2/go.mod h1:gvguwaGAFyv5/9KrcW9MkCgHALYD+e99mSM7pSCYYho=
github.com/gortc/turn v0.7.3 h1:CE72C79erbcsfa6L/QDhKztcl2kDq1UK20ImrJWDt/w=
github.com/gortc/turn v0.7.3/go.mod h1:gvguwaGAFyv5/9KrcW9MkCgHALYD+e99mSM7pSCYYho=
github.com/pion/logging v0.2.1 h1:LwASkBKZ+2ysGJ+jLv1E/9H1ge0k1nTfi1X+5zirkDk=
github.com/pion/logging v0.2.1/go.mod h1:k0/tDVsRCX2Mb2ZEmTqNa7CWsQPc+YYCB7Q+5pahoms=
github.com/pion/stun v0.3.0/go.mod h1:xrCld6XM+6GWDZdvjPlLMsTU21rNxnO6UO8XsAvHr/M=
@@ -10,10 +10,10 @@ github.com/pion/stun v0.3.1 h1:d09JJzOmOS8ZzIp8NppCMgrxGZpJ4Ix8qirfNYyI3BA=
github.com/pion/stun v0.3.1/go.mod h1:xrCld6XM+6GWDZdvjPlLMsTU21rNxnO6UO8XsAvHr/M=
github.com/pion/transport v0.7.0 h1:EsXN8TglHMlKZMo4ZGqwK6QgXBu0WYg7wfGMWIXsS+w=
github.com/pion/transport v0.7.0/go.mod h1:iWZ07doqOosSLMhZ+FXUTq+TamDoXSllxpbGcfkCmbE=
github.com/pion/turn v1.1.3 h1:3EWUqB5knWFeGjxdzuOSg28tJ288tQS0+nQOfv0u0vQ=
github.com/pion/turn v1.1.3/go.mod h1:2O2GFDGO6+hJ5gsyExDhoNHtVcacPB1NOyc81gkq0WA=
github.com/pion/turnc v0.0.5 h1:gUQJ5u69sFsBaVkGdg/koi70OSv459UOByf0QzFV00A=
github.com/pion/turnc v0.0.5/go.mod h1:PCWBabTwSi9/z5mRFPdiYOPjMpKuSK2WjzaLr2cqNsQ=
github.com/pion/turn v1.1.4 h1:yGxcasBvge4idNjxjowePn8oW43C4v70bXroBBKLyKY=
github.com/pion/turn v1.1.4/go.mod h1:2O2GFDGO6+hJ5gsyExDhoNHtVcacPB1NOyc81gkq0WA=
github.com/pion/turnc v0.0.6 h1:FHsmwYvdJ8mhT1/ZtWWer9L0unEb7AyRgrymfWy6mEY=
github.com/pion/turnc v0.0.6/go.mod h1:4MSFv5i0v3MRkDLdo5eF9cD/xJtj1pxSphHNnxKL2W8=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
+1 -1
View File
@@ -364,7 +364,7 @@ func copyCandidate(o Candidate) Candidate {
component: orig.component,
relatedAddress: orig.relatedAddress,
},
nil, nil,
nil, nil, nil,
}
default:
return nil