Skip to content

Commit

Permalink
fix: infinite loop when checking for write connection in peer
Browse files Browse the repository at this point in the history
  • Loading branch information
kuba-4chain committed Jul 2, 2024
1 parent 9e32c96 commit d0c778e
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -683,17 +683,15 @@ func (p *Peer) startWriteChannelHandler(ctx context.Context, instance int) {
p.logger.Debug("Write handler canceled", slog.Int("instance", instance))
return
case msg := <-p.writeChan:
p.mu.RLock()
writeConn := p.writeConn
p.mu.RUnlock()

for {
p.mu.RLock()
writeConn := p.writeConn
p.mu.RUnlock()

if writeConn != nil {
break
}
if writeConn == nil {
time.Sleep(100 * time.Millisecond)
continue
}

err := p.writeRetry(ctx, msg)
if err != nil {
if errors.Is(err, context.Canceled) {
Expand Down Expand Up @@ -732,6 +730,7 @@ func (p *Peer) startWriteChannelHandler(ctx context.Context, instance int) {
case *wire.MsgGetData:
p.logger.Debug(sentMsg, slog.String(commandKey, strings.ToUpper(message.Command())), slog.String(hashKey, m.InvList[0].Hash.String()), slog.String(typeKey, "getdata"))
case *wire.MsgInv:
p.logger.Debug(sentMsg, slog.String(commandKey, strings.ToUpper(message.Command())), slog.String(hashKey, m.InvList[0].Hash.String()), slog.String(typeKey, "inv"))
default:
p.logger.Debug(sentMsg, slog.String(commandKey, strings.ToUpper(message.Command())), slog.String(typeKey, "unknown"))
}
Expand Down

0 comments on commit d0c778e

Please sign in to comment.