From b9a7cbfa145d548133811719a02e32d927457d89 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Sat, 7 May 2016 19:02:30 +1000 Subject: [PATCH] dht: Fix race contacting starting addrs in Announce --- dht/announce.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/dht/announce.go b/dht/announce.go index cff0ac73..ead301a4 100644 --- a/dht/announce.go +++ b/dht/announce.go @@ -96,13 +96,15 @@ func (s *Server) Announce(infoHash string, port int, impliedPort bool) (*Announc } }() go func() { + disc.mu.Lock() + defer disc.mu.Unlock() for i, addr := range startAddrs { if i != 0 { + disc.mu.Unlock() time.Sleep(time.Millisecond) + disc.mu.Lock() } - disc.mu.Lock() disc.contact(addr) - disc.mu.Unlock() } disc.contactedStartAddrs = true // If we failed to contact any of the starting addrs, no transactions