Skip to content

Commit 6489a0d

Browse files
authored
ethdb/pebble: don't double-close iterator inside pebbleIterator (#28566)
Adds 'released' flag to pebbleIterator to avoid double closing cockroachdb/pebble.Iterator as it is an invalid operation. Fixes #28565
1 parent 146e8d9 commit 6489a0d

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
@@ -609,9 +609,12 @@ func (b *batch) Replay(w ethdb.KeyValueWriter) error {
609609

610610
// pebbleIterator is a wrapper of underlying iterator in storage engine.
611611
// The purpose of this structure is to implement the missing APIs.
612+
//
613+
// The pebble iterator is not thread-safe.
612614
type pebbleIterator struct {
613-
iter *pebble.Iterator
614-
moved bool
615+
iter *pebble.Iterator
616+
moved bool
617+
released bool
615618
}
616619

617620
// NewIterator creates a binary-alphabetical iterator over a subset
@@ -623,7 +626,7 @@ func (d *Database) NewIterator(prefix []byte, start []byte) ethdb.Iterator {
623626
UpperBound: upperBound(prefix),
624627
})
625628
iter.First()
626-
return &pebbleIterator{iter: iter, moved: true}
629+
return &pebbleIterator{iter: iter, moved: true, released: false}
627630
}
628631

629632
// Next moves the iterator to the next key/value pair. It returns whether the
@@ -658,4 +661,9 @@ func (iter *pebbleIterator) Value() []byte {
658661

659662
// Release releases associated resources. Release should always succeed and can
660663
// be called multiple times without causing error.
661-
func (iter *pebbleIterator) Release() { iter.iter.Close() }
664+
func (iter *pebbleIterator) Release() {
665+
if !iter.released {
666+
iter.iter.Close()
667+
iter.released = true
668+
}
669+
}

0 commit comments

Comments
 (0)