Skip to content

Commit 63a9395

Browse files
committed
ethdb/pebble: don't double-close iterator inside pebbleIterator (ethereum#28566)
Adds 'released' flag to pebbleIterator to avoid double closing cockroachdb/pebble.Iterator as it is an invalid operation. Fixes ethereum#28565
1 parent f4eec6e commit 63a9395

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

ethdb/pebble/pebble.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -567,9 +567,12 @@ func (b *batch) Replay(w ethdb.KeyValueWriter) error {
567567

568568
// pebbleIterator is a wrapper of underlying iterator in storage engine.
569569
// The purpose of this structure is to implement the missing APIs.
570+
//
571+
// The pebble iterator is not thread-safe.
570572
type pebbleIterator struct {
571-
iter *pebble.Iterator
572-
moved bool
573+
iter *pebble.Iterator
574+
moved bool
575+
released bool
573576
}
574577

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

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

617620
// Release releases associated resources. Release should always succeed and can
618621
// be called multiple times without causing error.
619-
func (iter *pebbleIterator) Release() { iter.iter.Close() }
622+
func (iter *pebbleIterator) Release() {
623+
if !iter.released {
624+
iter.iter.Close()
625+
iter.released = true
626+
}
627+
}

0 commit comments

Comments
 (0)