mirror of
https://github.com/syncthing/syncthing.git
synced 2024-11-16 10:28:49 -07:00
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:
parent
3dd13c3994
commit
415adfbae6
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user