diff --git a/immutable_tree.go b/immutable_tree.go index 54ccdf991..18a9929fc 100644 --- a/immutable_tree.go +++ b/immutable_tree.go @@ -193,7 +193,7 @@ func (t *ImmutableTree) Get(key []byte) ([]byte, error) { // If the tree is of the latest version and fast node is not in the tree // then the regular node is not in the tree either because fast node // represents live state. - if t.version == t.ndb.latestVersion { + if t.version == t.ndb.safeGetLatestVersion() { return nil, nil } diff --git a/nodedb.go b/nodedb.go index 829c5697d..fec69df6c 100644 --- a/nodedb.go +++ b/nodedb.go @@ -797,6 +797,15 @@ func (ndb *nodeDB) resetLegacyLatestVersion(version int64) { ndb.legacyLatestVersion = version } +// safeGetLatestVersion returns the value of ndb.latestVersion directly +// without additional logic performed by getLatestVersion. +func (ndb *nodeDB) safeGetLatestVersion() int64 { + ndb.mtx.Lock() + defer ndb.mtx.Unlock() + + return ndb.latestVersion +} + func (ndb *nodeDB) getLatestVersion() (int64, error) { ndb.mtx.Lock() latestVersion := ndb.latestVersion