Skip to content

Commit 7cf6a63

Browse files
core/state/snapshot: acquire the lock on Release (#30011)
* core/state/snapshot: acquire the lock on release * core/state/snapshot: only acquire read-lock when iterating
1 parent d866449 commit 7cf6a63

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

core/state/snapshot/snapshot.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,9 @@ func diffToDisk(bottom *diffLayer) *diskLayer {
666666

667667
// Release releases resources
668668
func (t *Tree) Release() {
669+
t.lock.RLock()
670+
defer t.lock.RUnlock()
671+
669672
if dl := t.disklayer(); dl != nil {
670673
dl.Release()
671674
}
@@ -850,8 +853,8 @@ func (t *Tree) diskRoot() common.Hash {
850853
// generating is an internal helper function which reports whether the snapshot
851854
// is still under the construction.
852855
func (t *Tree) generating() (bool, error) {
853-
t.lock.Lock()
854-
defer t.lock.Unlock()
856+
t.lock.RLock()
857+
defer t.lock.RUnlock()
855858

856859
layer := t.disklayer()
857860
if layer == nil {
@@ -864,8 +867,8 @@ func (t *Tree) generating() (bool, error) {
864867

865868
// DiskRoot is an external helper function to return the disk layer root.
866869
func (t *Tree) DiskRoot() common.Hash {
867-
t.lock.Lock()
868-
defer t.lock.Unlock()
870+
t.lock.RLock()
871+
defer t.lock.RUnlock()
869872

870873
return t.diskRoot()
871874
}

0 commit comments

Comments
 (0)