From ef8d65db27daa3d74eeba432804cff7e86c23aec Mon Sep 17 00:00:00 2001 From: Cool Developer Date: Wed, 13 Sep 2023 09:36:38 -0400 Subject: [PATCH] fix data race of latestVersion --- mutable_tree.go | 1 - nodedb.go | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/mutable_tree.go b/mutable_tree.go index 9694ab761..be2ec2694 100644 --- a/mutable_tree.go +++ b/mutable_tree.go @@ -797,7 +797,6 @@ func (tree *MutableTree) saveFastNodeVersion(isGenesis bool) error { return tree.ndb.setFastStorageVersionToBatch() } -// nolint: unused func (tree *MutableTree) getUnsavedFastNodeAdditions() map[string]*fastnode.Node { additions := make(map[string]*fastnode.Node) tree.unsavedFastNodeAdditions.Range(func(key, value interface{}) bool { diff --git a/nodedb.go b/nodedb.go index cf074db1a..8c22e06c9 100644 --- a/nodedb.go +++ b/nodedb.go @@ -733,6 +733,8 @@ func (ndb *nodeDB) getLatestVersion() (int64, error) { } func (ndb *nodeDB) resetLatestVersion(version int64) { + ndb.mtx.Lock() + defer ndb.mtx.Unlock() ndb.latestVersion = version }