From 01b85dc70b59b472692cb1efd1f6fe5eb8f8567f Mon Sep 17 00:00:00 2001 From: Noah Levenson Date: Wed, 19 Jul 2023 12:48:44 -0700 Subject: [PATCH 1/2] fix data race --- nats/discover.go | 6 ++++++ 1 file changed, 6 insertions(+) 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 } } From b7ef97adb292f4b98ca2da99de08a35ee7ca72d5 Mon Sep 17 00:00:00 2001 From: Noah Levenson Date: Wed, 19 Jul 2023 19:17:21 -0700 Subject: [PATCH 2/2] fix goroutine leak --- nats/discover.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/nats/discover.go b/nats/discover.go index 752064f..bcbd8be 100644 --- a/nats/discover.go +++ b/nats/discover.go @@ -335,6 +335,7 @@ func (nats *NATS) performTransactionWith(c *turn.Client, changeIP, changePort bo nats.dfErr = fmt.Errorf("CHANGE-REQUEST ignored (IP)") nats.mu.Unlock() receivedCh <- false + return } } if changePort { @@ -343,6 +344,7 @@ func (nats *NATS) performTransactionWith(c *turn.Client, changeIP, changePort bo nats.dfErr = fmt.Errorf("CHANGE-REQUEST ignored (Port)") nats.mu.Unlock() receivedCh <- false + return } }