Skip to content

fix(nodedb): fix race between updating fast node cache and db commit (backport #1142)#1147

Merged
mattac21 merged 3 commits into
release/v1.3.xfrom
mergify/bp/release/v1.3.x/pr-1142
Apr 6, 2026
Merged

fix(nodedb): fix race between updating fast node cache and db commit (backport #1142)#1147
mattac21 merged 3 commits into
release/v1.3.xfrom
mergify/bp/release/v1.3.x/pr-1142

Conversation

@mergify

@mergify mergify Bot commented Apr 6, 2026

Copy link
Copy Markdown
Contributor

Fixes a race condition where concurrent GetFastNode calls (from RPC queries) can repopulate the fast node cache with stale data that is about to be overridden from the tree during SaveVersion. After Commit within SaveVersion the cache is not repopulated with the correct data from the tree, causing the cache to serve that stale data to future readers. At the application level, this leads to an app hash mismatches.

To fix this, we introduce a pendingFastNodeAdditions and pendingFastNodeRemovals that store changes to the fast node cache when adding nodes via saveFastNodeUnlocked or DeleteFastNode. We then defer the addition or removal of nodes from the fast node cache until after the tree changes commit, meaning there is no period of time where we could have removed a node from the cache, then brought back up an incorrect value from the tree.

This also fixes a separate race between SaveVersion and accessing getLatestVersion that was exercised by the regression tests.


This is an automatic backport of pull request #1142 done by Mergify.

@mergify mergify Bot added the conflicts label Apr 6, 2026
@mergify

mergify Bot commented Apr 6, 2026

Copy link
Copy Markdown
Contributor Author

Cherry-pick of 146f723 has failed:

On branch mergify/bp/release/v1.3.x/pr-1142
Your branch is up to date with 'origin/release/v1.3.x'.

You are currently cherry-picking commit 146f723.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	modified:   immutable_tree.go
	modified:   mutable_tree.go
	modified:   nodedb_test.go

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   nodedb.go

To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally

@mattac21 mattac21 removed the conflicts label Apr 6, 2026
@mattac21 mattac21 merged commit 6eb2fb5 into release/v1.3.x Apr 6, 2026
5 of 6 checks passed
@mattac21 mattac21 deleted the mergify/bp/release/v1.3.x/pr-1142 branch April 6, 2026 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant