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 all commits
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
8 changes: 6 additions & 2 deletions ethmonitor/ethmonitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,13 +334,15 @@ func (m *Monitor) listenNewHead() <-chan uint64 {
goto reconnect
}

blockTimer := time.NewTimer(3 * m.options.ExpectedBlockInterval)
for {
blockTimer := time.NewTimer(3 * m.options.ExpectedBlockInterval)

select {
case <-m.ctx.Done():
// if we're done, we'll unsubscribe and close the nextBlock channel
sub.Unsubscribe()
close(nextBlock)
blockTimer.Stop()
return

case err := <-sub.Err():
Expand All @@ -350,6 +352,7 @@ func (m *Monitor) listenNewHead() <-chan uint64 {
sub.Unsubscribe()

streamingErrorLastTime = time.Now()
blockTimer.Stop()
goto reconnect

case <-blockTimer.C:
Expand All @@ -361,7 +364,7 @@ func (m *Monitor) listenNewHead() <-chan uint64 {
goto reconnect

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

latestHeadBlock.Store(newHead.Number.Uint64())
select {
Expand Down Expand Up @@ -395,6 +398,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