From 8b26d9475b6a2da486d8b2eb6acce4d025836ef4 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Tue, 11 Oct 2022 17:44:13 +0300 Subject: [PATCH] network: speculatively set GetAddrSent status Otherwise we routinely get "unexpected addr received" error. --- pkg/network/server.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/network/server.go b/pkg/network/server.go index 240f8125f..99a7291cd 100644 --- a/pkg/network/server.go +++ b/pkg/network/server.go @@ -1367,11 +1367,11 @@ func (s *Server) iteratePeersWithSendMsg(msg *Message, send func(Peer, context.C var ctx, cancel = context.WithTimeout(context.Background(), s.TimePerBlock/2) for _, peer := range peers { go func(p Peer, ctx context.Context, pkt []byte) { - err := send(p, ctx, pkt) - if err == nil && msg.Command == CMDGetAddr { + // Do this before packet is sent, reader thread can get the reply before this routine wakes up. + if msg.Command == CMDGetAddr { p.AddGetAddrSent() } - replies <- err + replies <- send(p, ctx, pkt) }(peer, ctx, pkt) } for r := range replies {