ethdb/pebble: don't close twice underlying iterator of pebbleIterator

Adds released flag to pebbleIterator to avoid double closing cockroachdb/pebble.Iterator as it is an invalid operation.

Fixes #28565
This commit is contained in:
Maciej Kulawik 2023-11-20 19:14:29 +00:00
parent c8a2202028
commit 07c664e8f3

View file

@ -610,8 +610,9 @@ func (b *batch) Replay(w ethdb.KeyValueWriter) error {
// pebbleIterator is a wrapper of underlying iterator in storage engine. // pebbleIterator is a wrapper of underlying iterator in storage engine.
// The purpose of this structure is to implement the missing APIs. // The purpose of this structure is to implement the missing APIs.
type pebbleIterator struct { type pebbleIterator struct {
iter *pebble.Iterator iter *pebble.Iterator
moved bool moved bool
released bool
} }
// NewIterator creates a binary-alphabetical iterator over a subset // NewIterator creates a binary-alphabetical iterator over a subset
@ -623,7 +624,7 @@ func (d *Database) NewIterator(prefix []byte, start []byte) ethdb.Iterator {
UpperBound: upperBound(prefix), UpperBound: upperBound(prefix),
}) })
iter.First() 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 // Next moves the iterator to the next key/value pair. It returns whether the
@ -658,4 +659,9 @@ func (iter *pebbleIterator) Value() []byte {
// Release releases associated resources. Release should always succeed and can // Release releases associated resources. Release should always succeed and can
// be called multiple times without causing error. // 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
}
}