commitment: move cleanup to Release() for safer sync.Pool reuse#20208
Merged
Conversation
Move resetForReuse() from Get side (NewHexPatriciaHashed) to Release side. This ensures all mutable state is cleared before the object enters the pool: - PatriciaContext (database cursor) is nil'd — no stale DB references - WarmupCache is released - Large transient data (maps, buffers) is freed promptly for GC NewHexPatriciaHashed no longer needs to call resetForReuse() since: - Objects from pool already cleaned by Release() - newHexPatriciaHashed() produces a correctly zero-initialized struct Co-authored-by: shuo <shuo@erigon.dev>
AskAlexSharov
approved these changes
Mar 27, 2026
…d removal After merging main (94a38e6 removed ctx [16]PatriciaContext from ConcurrentPatriciaHashed), Release() still referenced p.ctx[i] = nil causing compile error. Replace with proper ctxClosers cleanup. Co-authored-by: shuo <shuo@erigon.dev>
yperbasis
pushed a commit
that referenced
this pull request
Mar 31, 2026
## Summary Moves `resetForReuse()` from the Get side (`NewHexPatriciaHashed`) to the Release side (`Release()`), so objects are always clean when they enter the pool rather than when they exit. ### Before Objects were cleaned in `NewHexPatriciaHashed` on the way out of the pool. While pool objects were eventually cleaned, freshly allocated objects bypassed `resetForReuse()` and any stale references in the pool were live until the next Get. ### After `Release()` now calls `resetForReuse()` before returning the object to the pool: - `PatriciaContext` (database cursor) is nil'd — no stale DB references survive in pool - `WarmupCache` is released immediately - Large transient data (maps, buffers) is freed for GC promptly - `NewHexPatriciaHashed` no longer needs `resetForReuse()` since pool objects are already clean and `newHexPatriciaHashed()` produces a correctly zero-initialized struct Co-authored-by: shuo <shuo@erigon.dev> --------- Co-authored-by: shuo <shuo@erigon.dev>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Moves
resetForReuse()from the Get side (NewHexPatriciaHashed) to the Release side (Release()), so objects are always clean when they enter the pool rather than when they exit.Before
Objects were cleaned in
NewHexPatriciaHashedon the way out of the pool. While pool objects were eventually cleaned, freshly allocated objects bypassedresetForReuse()and any stale references in the pool were live until the next Get.After
Release()now callsresetForReuse()before returning the object to the pool:PatriciaContext(database cursor) is nil'd — no stale DB references survive in poolWarmupCacheis released immediatelyNewHexPatriciaHashedno longer needsresetForReuse()since pool objects are already clean andnewHexPatriciaHashed()produces a correctly zero-initialized structCo-authored-by: shuo shuo@erigon.dev