Skip to content

Commit a8f7024

Browse files
committed
fix: panic: sync: unlock of unlocked mutex
Update CHANGELOG.md cleanup
1 parent 0e4c40f commit a8f7024

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Bug Fixes
66

77
- [#1007](https://github.com/cosmos/iavl/pull/1007) Add the extra check for the reformatted root node in `GetNode`
8+
- [#1106](https://github.com/cosmos/iavl/pull/1106) Fix unlock of unlocked mutex panic.
89

910
### Improvements
1011

batch.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,9 @@ func (b *BatchWithFlusher) Set(key, value []byte) error {
5757
return err
5858
}
5959
if batchSizeAfter > b.flushThreshold {
60-
b.mtx.Unlock()
61-
if err := b.Write(); err != nil {
60+
if err := b.write(); err != nil {
6261
return err
6362
}
64-
b.mtx.Lock()
6563
}
6664
return b.batch.Set(key, value)
6765
}
@@ -79,19 +77,14 @@ func (b *BatchWithFlusher) Delete(key []byte) error {
7977
return err
8078
}
8179
if batchSizeAfter > b.flushThreshold {
82-
b.mtx.Unlock()
83-
if err := b.Write(); err != nil {
80+
if err := b.write(); err != nil {
8481
return err
8582
}
86-
b.mtx.Lock()
8783
}
8884
return b.batch.Delete(key)
8985
}
9086

91-
func (b *BatchWithFlusher) Write() error {
92-
b.mtx.Lock()
93-
defer b.mtx.Unlock()
94-
87+
func (b *BatchWithFlusher) write() error {
9588
if err := b.batch.Write(); err != nil {
9689
return err
9790
}
@@ -102,6 +95,13 @@ func (b *BatchWithFlusher) Write() error {
10295
return nil
10396
}
10497

98+
func (b *BatchWithFlusher) Write() error {
99+
b.mtx.Lock()
100+
defer b.mtx.Unlock()
101+
102+
return b.write()
103+
}
104+
105105
func (b *BatchWithFlusher) WriteSync() error {
106106
b.mtx.Lock()
107107
defer b.mtx.Unlock()

0 commit comments

Comments
 (0)