but in case the erroring condition matches, it'll be locked forever. Let's fix that by 2 ways
[ ] A dedicated closure with an error return
err := func() error {
ndb.mtx.Lock()
defer ndb.mtx.Unlock()
for v, r := range ndb.versionReaders {
if v >= fromVersion && r != 0 {
return fmt.Errorf("unable to delete version %v with %v active readers", v, r)
}
}
return nil
}()
[ ] Manually unlocking in the error path
ndb.mtx.Lock()
for v, r := range ndb.versionReaders {
if v >= fromVersion && r != 0 {
ndb.mtx.Unlock()
return fmt.Errorf("unable to delete version %v with %v active readers", v, r)
}
}
ndb.mtx.Unlock()
Noticed in an audit and while preparing a test for P #838 that this code exists https://github.com/cosmos/iavl/blob/3574b99d1cb0f06591c2bd02cba47bef7ebc9312/nodedb.go#L493-L499
but in case the erroring condition matches, it'll be locked forever. Let's fix that by 2 ways
[ ] A dedicated closure with an error return
[ ] Manually unlocking in the error path
/cc @elias-orijtech