Skip to content

Commit d0c778e

Browse files
committed
fix: infinite loop when checking for write connection in peer
1 parent 9e32c96 commit d0c778e

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

peer.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -683,17 +683,15 @@ func (p *Peer) startWriteChannelHandler(ctx context.Context, instance int) {
683683
p.logger.Debug("Write handler canceled", slog.Int("instance", instance))
684684
return
685685
case msg := <-p.writeChan:
686+
p.mu.RLock()
687+
writeConn := p.writeConn
688+
p.mu.RUnlock()
686689

687-
for {
688-
p.mu.RLock()
689-
writeConn := p.writeConn
690-
p.mu.RUnlock()
691-
692-
if writeConn != nil {
693-
break
694-
}
690+
if writeConn == nil {
695691
time.Sleep(100 * time.Millisecond)
692+
continue
696693
}
694+
697695
err := p.writeRetry(ctx, msg)
698696
if err != nil {
699697
if errors.Is(err, context.Canceled) {
@@ -732,6 +730,7 @@ func (p *Peer) startWriteChannelHandler(ctx context.Context, instance int) {
732730
case *wire.MsgGetData:
733731
p.logger.Debug(sentMsg, slog.String(commandKey, strings.ToUpper(message.Command())), slog.String(hashKey, m.InvList[0].Hash.String()), slog.String(typeKey, "getdata"))
734732
case *wire.MsgInv:
733+
p.logger.Debug(sentMsg, slog.String(commandKey, strings.ToUpper(message.Command())), slog.String(hashKey, m.InvList[0].Hash.String()), slog.String(typeKey, "inv"))
735734
default:
736735
p.logger.Debug(sentMsg, slog.String(commandKey, strings.ToUpper(message.Command())), slog.String(typeKey, "unknown"))
737736
}

0 commit comments

Comments
 (0)