Skip to content

commitment: move cleanup to Release() for safer sync.Pool reuse#20208

Merged
awskii merged 3 commits into
mainfrom
awskii/pool-release
Mar 30, 2026
Merged

commitment: move cleanup to Release() for safer sync.Pool reuse#20208
awskii merged 3 commits into
mainfrom
awskii/pool-release

Conversation

@awskii

@awskii awskii commented Mar 27, 2026

Copy link
Copy Markdown
Member

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

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>
@awskii awskii added this pull request to the merge queue Mar 30, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Mar 30, 2026
@awskii awskii added this pull request to the merge queue Mar 30, 2026
@awskii awskii removed this pull request from the merge queue due to a manual request Mar 30, 2026
awskii and others added 2 commits March 30, 2026 09:11
…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>
@awskii awskii added this pull request to the merge queue Mar 30, 2026
Merged via the queue into main with commit 59e3b08 Mar 30, 2026
35 checks passed
@awskii awskii deleted the awskii/pool-release branch March 30, 2026 10:51
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>
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.

2 participants