diff --git a/nats/discover.go b/nats/discover.go index 64b1d25..752064f 100644 --- a/nats/discover.go +++ b/nats/discover.go @@ -4,6 +4,7 @@ import ( "fmt" "log" "net" + "sync" "github.com/pion/logging" "github.com/pion/stun" @@ -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. @@ -329,13 +331,17 @@ 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 } } 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 } }