Skip to content

Commit

Permalink
core/rawdb: fix leak of backoff timer (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanmorphl2 authored Jun 12, 2024
1 parent e89d00a commit ca14e80
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions core/rawdb/freezer.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ const (
// freezer is an memory mapped append-only database to store immutable chain data
// into flat files:
//
// - The append only nature ensures that disk writes are minimized.
// - The memory mapping ensures we can max out system memory for caching without
// reserving it for go-ethereum. This would also reduce the memory requirements
// of Geth, and thus also GC overhead.
// - The append only nature ensures that disk writes are minimized.
// - The memory mapping ensures we can max out system memory for caching without
// reserving it for go-ethereum. This would also reduce the memory requirements
// of Geth, and thus also GC overhead.
type freezer struct {
// WARNING: The `frozen` field is accessed atomically. On 32 bit platforms, only
// 64-bit aligned fields can be atomic. The struct is guaranteed to be so aligned,
Expand Down Expand Up @@ -205,9 +205,9 @@ func (f *freezer) Ancient(kind string, number uint64) ([]byte, error) {

// AncientRange retrieves multiple items in sequence, starting from the index 'start'.
// It will return
// - at most 'max' items,
// - at least 1 item (even if exceeding the maxByteSize), but will otherwise
// return as many items as fit into maxByteSize.
// - at most 'max' items,
// - at least 1 item (even if exceeding the maxByteSize), but will otherwise
// return as many items as fit into maxByteSize.
func (f *freezer) AncientRange(kind string, start, count, maxBytes uint64) ([][]byte, error) {
if table := f.tables[kind]; table != nil {
return table.RetrieveItems(start, count, maxBytes)
Expand Down Expand Up @@ -339,6 +339,8 @@ func (f *freezer) freeze(db ethdb.KeyValueStore) {
backoff bool
triggered chan struct{} // Used in tests
)
timer := time.NewTimer(freezerRecheckInterval)
defer timer.Stop()
for {
select {
case <-f.quit:
Expand All @@ -353,8 +355,9 @@ func (f *freezer) freeze(db ethdb.KeyValueStore) {
triggered = nil
}
select {
case <-time.NewTimer(freezerRecheckInterval).C:
case <-timer.C:
backoff = false
timer.Reset(freezerRecheckInterval)
case triggered = <-f.trigger:
backoff = false
case <-f.quit:
Expand Down

0 comments on commit ca14e80

Please sign in to comment.