Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ethmonitor temporary resource leak #120

Merged
merged 3 commits into from
Apr 16, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this would create an extra channel + timeout interrupt in each for loop iteration

I think let's stick to blockTimer -- and stop it on error / ctx done

// 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
Loading