Skip to content

core/state/snapshot: fix generator shutdown race (backport ethereum/go-ethereum#33540)#286

Merged
rahulmutt-ava merged 2 commits into
mainfrom
rahulmutt/backport-geth-33540
Jun 11, 2026
Merged

core/state/snapshot: fix generator shutdown race (backport ethereum/go-ethereum#33540)#286
rahulmutt-ava merged 2 commits into
mainfrom
rahulmutt/backport-geth-33540

Conversation

@rahulmutt-ava

Copy link
Copy Markdown

Why this should be merged

This is a backport of the PR @JonathanOppenheimer submitted (and got merged) to upstream, so mostly should be pretty similar.

How this works

See the upstream PR. The easiest way to review this is to open the upstream PR and look at the differences side by side to see what is different. You'll notice that core/state/snapshot/snapshot.go is different in this backport in that there are two additional replacements of aborting being replaced with stopGeneration. Everything else is more or less the same.

How this was tested

The test was backported as well.

…3540)

The snapshot generator goroutine parked waiting for a genAbort signal even
after generation completed, and diskLayer.Release() never sent it. On
shutdown the goroutine lingered and could access the trie database after it
was closed, causing iterator failures.

Replace the genAbort request/reply channel with a cancel/done broadcast
model and an idempotent, blocking stopGeneration(); Release() now stops the
generator. Also converts Tree.Disable()/Tree.Rebuild() to stopGeneration()
(upstream had already done this; libevm predated that refactor).

Backport of ethereum#33540.
@ARR4N

ARR4N commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

I'll wait for @JonathanOppenheimer's review as original author before doing mine so it's in a stable position.

I think we should be tracking this in #128 as it will definitely result in conflicts if we don't revert it before the merge. In which version was this introduced into geth?

@rahulmutt-ava

Copy link
Copy Markdown
Author

It was merged 5 days ago in ethereum@bc1967f so not included in a version yet. Given the geth release cadence I'd expect a new release will be about with this fix by the time we merge, but even if not, we could merge just that PR cleanly. Once we merge this, I'll be sure to add the maintenance notes to #128.

@JonathanOppenheimer

JonathanOppenheimer commented Jun 9, 2026

Copy link
Copy Markdown

In which version was this introduced into geth?

It'll be in 1.17.4: https://github.com/ethereum/go-ethereum/milestone/201, and yeah agree to add it to the list!

@JonathanOppenheimer JonathanOppenheimer left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd revert the typo fix, but this LGTM if this is the solution path we want to take. Given that we are cherry-picking this "prematurely", we will have to manually revert it I believe when updating geth, but this is something Austin does need.

Comment thread core/state/snapshot/generate.go
Comment thread core/state/snapshot/disklayer.go
Comment thread core/state/snapshot/generate_test.go Outdated
Comment thread core/state/snapshot/snapshot.go
Comment thread core/state/snapshot/snapshot.go
Fix typo in comment regarding goroutine snapshot.

Signed-off-by: Rahul Muttineni <rahul.muttineni@avalabs.org>
@rahulmutt-ava rahulmutt-ava requested a review from ARR4N June 9, 2026 17:51
@rahulmutt-ava

Copy link
Copy Markdown
Author

@ARR4N it's ready for review. I kept the Jonathan's comments unresolved so that it's easy for you to review as well.

@alarso16 alarso16 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This diff looks comparable, and I verified this fixed my issue in ava-labs/avalanchego#5482

@ARR4N ARR4N left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seeing as this has already had so many eyes on it, including upstream approval, consider my comments just as questions for my own understanding.

Comment thread core/state/snapshot/disklayer.go
Comment thread core/state/snapshot/generate.go
Comment thread core/state/snapshot/snapshot.go
@rahulmutt-ava rahulmutt-ava merged commit 2e3b1cb into main Jun 11, 2026
13 checks passed
@rahulmutt-ava rahulmutt-ava deleted the rahulmutt/backport-geth-33540 branch June 11, 2026 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants