stunner: fix data race.

In very low-latency conditions, a STUN request can complete before
the startup loop has finished firing off goroutines, leading to
a concurrent map mutation.
This commit is contained in:
David Anderson 2020-03-25 23:11:22 -07:00
parent 7fb8d873ac
commit dbca186a64
1 changed files with 2 additions and 0 deletions

View File

@ -184,6 +184,7 @@ func (s *Stunner) Run(ctx context.Context) error {
defer cancel()
need[server] = sender{ctx, cancel}
}
needMu.Lock()
for server, sender := range need {
wg.Add(1)
server, ctx := server, sender.ctx
@ -192,6 +193,7 @@ func (s *Stunner) Run(ctx context.Context) error {
s.sendPackets(ctx, server)
}()
}
needMu.Unlock()
var err error
select {
case <-ctx.Done():