lib/db: Don't hang on double iterator release with Badger (#6960)

Since iterators must be released before committing or discarding a
transaction we have the pattern of both deferring a release plus doing
it manually. But we can't release twice because we track this with a
WaitGroup that will panic when there are more Done()s than Add()s. This
just adds a boolean to let an iterator keep track.
This commit is contained in:
Jakob Borg 2020-09-07 10:31:33 +02:00 committed by GitHub
parent 3dd13c3994
commit 415adfbae6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -334,6 +334,7 @@ type badgerIterator struct {
first []byte
last []byte
releaseFn func()
released bool
didSeek bool
err error
}
@ -397,6 +398,12 @@ func (i *badgerIterator) Error() error {
}
func (i *badgerIterator) Release() {
if i.released {
// We already closed this iterator, no need to do it again
// (and the releaseFn might hang if we do).
return
}
i.released = true
i.it.Close()
if i.releaseFn != nil {
i.releaseFn()