Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix second goroutine leak #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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 nats/discover.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"log"
"net"
"sync"

"github.com/pion/logging"
"github.com/pion/stun"
Expand Down Expand Up @@ -60,6 +61,7 @@ type NATS struct {
verbose bool
net *vnet.Net
dfErr error // filled by discoverFilteringBehavior
mu sync.Mutex
}

// NewNATS creats a new instance of NATS.
Expand Down Expand Up @@ -148,6 +150,7 @@ func (nats *NATS) Discover() (*DiscoverResult, error) {
var maddr stun.XORMappedAddress
if err = maddr.GetFrom(trRes.Msg); err != nil {
if err != nil {
<-filterDiscovDone
return nil, fmt.Errorf("XOR-MAPPED-ADDRESS not found")
}
}
Expand All @@ -165,6 +168,7 @@ func (nats *NATS) Discover() (*DiscoverResult, error) {
var caddr attrAddress
if err = caddr.getAs(trRes.Msg, attrTypeChangedAddress); err != nil {
if err != nil {
<-filterDiscovDone
return nil, fmt.Errorf("CHANGED-ADDRESS not found")
}
}
Expand Down Expand Up @@ -329,14 +333,20 @@ func (nats *NATS) performTransactionWith(c *turn.Client, changeIP, changePort bo
from := res.From.(*net.UDPAddr)
if changeIP {
if from.IP.Equal(c.STUNServerAddr().(*net.UDPAddr).IP) {
nats.mu.Lock()
nats.dfErr = fmt.Errorf("CHANGE-REQUEST ignored (IP)")
nats.mu.Unlock()
receivedCh <- false
return
}
}
if changePort {
if from.Port == c.STUNServerAddr().(*net.UDPAddr).Port {
nats.mu.Lock()
nats.dfErr = fmt.Errorf("CHANGE-REQUEST ignored (Port)")
nats.mu.Unlock()
receivedCh <- false
return
}
}

Expand Down