Skip to content

Commit 73b5302

Browse files
committed
move semaphore before opening stream in sendDelta
1 parent c488a1c commit 73b5302

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

p2p/protocol/identify/peer_loop.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -115,17 +115,17 @@ func (ph *peerHandler) sendDelta(ctx context.Context) error {
115115
return nil
116116
}
117117

118-
ph.ids.pushSemaphore <- struct{}{}
119-
defer func() {
120-
<-ph.ids.pushSemaphore
121-
}()
122-
123118
// extract a delta message, updating the last state.
124119
mes := ph.nextDelta()
125120
if mes == nil || (len(mes.AddedProtocols) == 0 && len(mes.RmProtocols) == 0) {
126121
return nil
127122
}
128123

124+
ph.ids.pushSemaphore <- struct{}{}
125+
defer func() {
126+
<-ph.ids.pushSemaphore
127+
}()
128+
129129
ds, err := ph.openStream(ctx, []string{IDDelta})
130130
if err != nil {
131131
return fmt.Errorf("failed to open delta stream: %w", err)

0 commit comments

Comments
 (0)