From 73b53024cbf83e3393f848185eb9bc429b0699b8 Mon Sep 17 00:00:00 2001 From: vyzo Date: Fri, 21 Jan 2022 09:48:46 +0200 Subject: [PATCH] move semaphore before opening stream in sendDelta --- p2p/protocol/identify/peer_loop.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/p2p/protocol/identify/peer_loop.go b/p2p/protocol/identify/peer_loop.go index c2dc4581fb..828f106473 100644 --- a/p2p/protocol/identify/peer_loop.go +++ b/p2p/protocol/identify/peer_loop.go @@ -115,17 +115,17 @@ func (ph *peerHandler) sendDelta(ctx context.Context) error { return nil } - ph.ids.pushSemaphore <- struct{}{} - defer func() { - <-ph.ids.pushSemaphore - }() - // extract a delta message, updating the last state. mes := ph.nextDelta() if mes == nil || (len(mes.AddedProtocols) == 0 && len(mes.RmProtocols) == 0) { return nil } + ph.ids.pushSemaphore <- struct{}{} + defer func() { + <-ph.ids.pushSemaphore + }() + ds, err := ph.openStream(ctx, []string{IDDelta}) if err != nil { return fmt.Errorf("failed to open delta stream: %w", err)