Skip to content

Commit

Permalink
refactor(internal/statesync): replace ticker with time.After(X) (co…
Browse files Browse the repository at this point in the history
…metbft#2294)

- Remove `defer` from `ticker.Stop()` inside the loop.
- Manually call `ticker.Stop()` at necessary points in the loop to
ensure tickers are stopped correctly after each iteration.

---------

Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
  • Loading branch information
hoanguyenkh and melekes authored Feb 12, 2024
1 parent 1d4b668 commit 0820cd5
Showing 1 changed file with 1 addition and 6 deletions.
7 changes: 1 addition & 6 deletions internal/statesync/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,23 +440,18 @@ func (s *syncer) fetchChunks(ctx context.Context, snapshot *snapshot, chunks *ch
s.logger.Info("Fetching snapshot chunk", "height", snapshot.Height,
"format", snapshot.Format, "chunk", index, "total", chunks.Size())

ticker := time.NewTicker(s.retryTimeout)
defer ticker.Stop()

s.requestChunk(snapshot, index)

select {
case <-chunks.WaitFor(index):
next = true

case <-ticker.C:
case <-time.After(s.retryTimeout):
next = false

case <-ctx.Done():
return
}

ticker.Stop()
}
}

Expand Down

0 comments on commit 0820cd5

Please sign in to comment.