Skip to content

Commit

Permalink
Fixes: timer resource leak where it can be garbage collected only aft…
Browse files Browse the repository at this point in the history
…er it fires
  • Loading branch information
marino39 committed Apr 16, 2024
1 parent b69b303 commit 1768160
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions ethmonitor/ethmonitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,6 @@ func (m *Monitor) listenNewHead() <-chan uint64 {
goto reconnect
}

blockTimer := time.NewTimer(3 * m.options.ExpectedBlockInterval)
for {
select {
case <-m.ctx.Done():
Expand All @@ -352,7 +351,7 @@ func (m *Monitor) listenNewHead() <-chan uint64 {
streamingErrorLastTime = time.Now()
goto reconnect

case <-blockTimer.C:
case <-time.After(3 * m.options.ExpectedBlockInterval):
// if we haven't received a new block in a while, we'll reconnect.
m.log.Warnf("ethmonitor: haven't received block in expected time, reconnecting..")
sub.Unsubscribe()
Expand All @@ -361,8 +360,6 @@ func (m *Monitor) listenNewHead() <-chan uint64 {
goto reconnect

case newHead := <-newHeads:
blockTimer.Reset(3 * m.options.ExpectedBlockInterval)

latestHeadBlock.Store(newHead.Number.Uint64())
select {
case nextBlock <- newHead.Number.Uint64():
Expand Down Expand Up @@ -395,6 +392,7 @@ func (m *Monitor) listenNewHead() <-chan uint64 {
case <-m.ctx.Done():
// if we're done, we'll close the nextBlock channel
close(nextBlock)
retryStreamingTimer.Stop()
return

case <-time.After(time.Duration(m.pollInterval.Load())):
Expand Down

0 comments on commit 1768160

Please sign in to comment.