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

ethdb/pebble: don't double-close iterator inside pebbleIterator #273

Merged
merged 1 commit into from
Nov 22, 2023
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
16 changes: 12 additions & 4 deletions ethdb/pebble/pebble.go
Original file line number Diff line number Diff line change
Expand Up @@ -567,9 +567,12 @@ func (b *batch) Replay(w ethdb.KeyValueWriter) error {

// pebbleIterator is a wrapper of underlying iterator in storage engine.
// The purpose of this structure is to implement the missing APIs.
//
// The pebble iterator is not thread-safe.
type pebbleIterator struct {
iter *pebble.Iterator
moved bool
iter *pebble.Iterator
moved bool
released bool
}

// NewIterator creates a binary-alphabetical iterator over a subset
Expand All @@ -581,7 +584,7 @@ func (d *Database) NewIterator(prefix []byte, start []byte) ethdb.Iterator {
UpperBound: upperBound(prefix),
})
iter.First()
return &pebbleIterator{iter: iter, moved: true}
return &pebbleIterator{iter: iter, moved: true, released: false}
}

// Next moves the iterator to the next key/value pair. It returns whether the
Expand Down Expand Up @@ -616,4 +619,9 @@ func (iter *pebbleIterator) Value() []byte {

// Release releases associated resources. Release should always succeed and can
// be called multiple times without causing error.
func (iter *pebbleIterator) Release() { iter.iter.Close() }
func (iter *pebbleIterator) Release() {
if !iter.released {
iter.iter.Close()
iter.released = true
}
}