Skip to content

Commit

Permalink
move semaphore before opening stream in sendDelta
Browse files Browse the repository at this point in the history
  • Loading branch information
vyzo committed Jan 21, 2022
1 parent c488a1c commit 73b5302
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions p2p/protocol/identify/peer_loop.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 73b5302

Please sign in to comment.