Skip to content

Commit

Permalink
fix: check for channel close when waiting for new blocks (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
agaffney authored May 28, 2024
1 parent 6fa12d7 commit 411bced
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions chainsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,14 @@ func (n *Node) chainsyncServerRequestNext(
clientState.NeedsInitialRollback = false
return nil
}
outerLoop:
for {
sentAwaitReply := false
select {
case block := <-clientState.BlockChan:
case block, ok := <-clientState.BlockChan:
if !ok {
break outerLoop
}
// Ignore blocks older than what we've already sent
if clientState.Cursor.SlotNumber >= block.Point.SlotNumber {
continue
Expand All @@ -133,7 +137,10 @@ func (n *Node) chainsyncServerRequestNext(
}
// Wait for next block and send
go func() {
block := <-clientState.BlockChan
block, ok := <-clientState.BlockChan
if !ok {
return
}
_ = n.chainsyncServerSendNext(ctx, block)
}()
sentAwaitReply = true
Expand Down

0 comments on commit 411bced

Please sign in to comment.