From dbca186a6456b73e747bb665159ea03d212b8cd6 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Wed, 25 Mar 2020 23:11:22 -0700 Subject: [PATCH] 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. --- stunner/stunner.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/stunner/stunner.go b/stunner/stunner.go index 534f617f9..41cb868e8 100644 --- a/stunner/stunner.go +++ b/stunner/stunner.go @@ -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():