Skip to content

Commit

Permalink
fix: Better lock handling on close (#1023)
Browse files Browse the repository at this point in the history
  • Loading branch information
alpe authored Dec 17, 2024
1 parent b74859b commit dfc90b0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## v1.3.4, December 17, 2024

- [#1023](https://github.com/cosmos/iavl/pull/1023) Better lock handling on close


## v1.3.3, December 16, 2024

- [#1018](https://github.com/cosmos/iavl/pull/1018) Cache first version for legacy versions, fix performance regression after upgrade.
Expand Down
9 changes: 5 additions & 4 deletions nodedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ func (ndb *nodeDB) startPruning() {
for {
select {
case <-ndb.ctx.Done():
ndb.done <- struct{}{}
close(ndb.done)
return
default:
ndb.mtx.Lock()
Expand Down Expand Up @@ -1122,14 +1122,15 @@ func (ndb *nodeDB) traverseOrphans(prevVersion, curVersion int64, fn func(*Node)

// Close the nodeDB.
func (ndb *nodeDB) Close() error {
ndb.mtx.Lock()
defer ndb.mtx.Unlock()

ndb.cancel()

if ndb.opts.AsyncPruning {
<-ndb.done // wait for the pruning process to finish
}

ndb.mtx.Lock()
defer ndb.mtx.Unlock()

if ndb.batch != nil {
if err := ndb.batch.Close(); err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions nodedb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,4 +444,5 @@ func TestCloseNodeDB(t *testing.T) {
opts.AsyncPruning = true
ndb := newNodeDB(db, 0, opts, NewNopLogger())
require.NoError(t, ndb.Close())
require.NoError(t, ndb.Close()) // must not block or fail on second call
}

0 comments on commit dfc90b0

Please sign in to comment.