From 116ba6b1118d6acb8f68a2b271d8b337a00d9e42 Mon Sep 17 00:00:00 2001 From: Aleksandr Razumov Date: Fri, 7 Jun 2019 23:56:35 +0300 Subject: [PATCH] Add turn client Close support Fix the goroutine leak. --- candidate_relay.go | 10 ++++++++-- gather.go | 2 +- go.mod | 4 ++-- go.sum | 12 ++++++------ transport_test.go | 2 +- 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/candidate_relay.go b/candidate_relay.go index f4ed5be..12f9f92 100644 --- a/candidate_relay.go +++ b/candidate_relay.go @@ -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 { diff --git a/gather.go b/gather.go index fb3a906..60187b7 100644 --- a/gather.go +++ b/gather.go @@ -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) diff --git a/go.mod b/go.mod index c3b3e22..632d0f8 100644 --- a/go.mod +++ b/go.mod @@ -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 ) diff --git a/go.sum b/go.sum index a6918f6..bab2304 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/transport_test.go b/transport_test.go index 176fd0a..5b8dc97 100644 --- a/transport_test.go +++ b/transport_test.go @@ -364,7 +364,7 @@ func copyCandidate(o Candidate) Candidate { component: orig.component, relatedAddress: orig.relatedAddress, }, - nil, nil, + nil, nil, nil, } default: return nil