From 4de71fdd4f3882ff4d4ed3343c37c276558e3a0e Mon Sep 17 00:00:00 2001 From: cool-developer <51834436+cool-develope@users.noreply.github.com> Date: Wed, 13 Sep 2023 09:53:44 -0400 Subject: [PATCH] fix: data race of latestVersion (#834) --- 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 }