Skip to content

Commit

Permalink
Merge pull request #24 from kuba-4chain/fix/infinite-loop
Browse files Browse the repository at this point in the history
fix: infinite loop when checking for write connection in peer
  • Loading branch information
boecklim authored Jul 3, 2024
2 parents 9e32c96 + d0c778e commit f57e79b
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 f57e79b

Please sign in to comment.