diff --git a/lib/db/backend/badger_backend.go b/lib/db/backend/badger_backend.go
index <HASH>..<HASH> 100644
--- a/lib/db/backend/badger_backend.go
+++ b/lib/db/backend/badger_backend.go
@@ -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()
lib/db: Don't hang on double iterator release with Badger (#<I>)

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.