Skip to content

Fix memory leaks in corpus pruner, trieDB, and RPC pool#812

Merged
anishnaik merged 1 commit intomasterfrom
dev/memory-leak-hotfixes
Mar 10, 2026
Merged

Fix memory leaks in corpus pruner, trieDB, and RPC pool#812
anishnaik merged 1 commit intomasterfrom
dev/memory-leak-hotfixes

Conversation

@anishnaik
Copy link
Copy Markdown
Collaborator

Summary

  • Corpus pruner coverage retention (+8 MB/min): PruneSequences replays sequences but checkSequenceCoverageAndUpdate only cleans coverage from the last element. Intermediate elements retain *CoverageMaps in AdditionalResults via ChainReference.Block pointers. Added cleanup loop for all elements after each replay, matching the pattern in Corpus.Initialize.
  • TrieDB hashdb growth (+2 MB/min): PendingBlockCommit calls state.Commit() inserting dirty trie nodes, but RevertToBlockIndex never called Dereference() to release old state roots. Added Dereference on revert and Cap(16 MB) on commit as a safety net.
  • Fork-mode inflightRequests (unbounded): ClientPool.launchRequest never deleted completed entries from the map. Passed the request key and added a deferred delete.

All three leaks confirmed via pprof profiling against aave-v4-scfuzzbench (~10 MB/min combined).

See #811 for a proposal to unify coverage cleanup long-term.

Test plan

  • go build ./... compiles
  • go vet ./... passes
  • golangci-lint run --timeout 5m ./chain/... ./fuzzing/... — no new warnings
  • go test -v -run 'TestFuzzerHooks|TestSlitherPrinter' ./fuzzing/... passes
  • pprof profiling shows eliminated coverage/trieDB growth and bounded inflightRequests

🤖 Generated with Claude Code

Three leaks confirmed via pprof profiling against aave-v4-scfuzzbench
(~10 MB/min combined growth):

1. Coverage maps retained in PruneSequences: checkSequenceCoverageAndUpdate
   only cleaned coverage from the last element. Intermediate elements held
   *CoverageMaps in AdditionalResults via ChainReference.Block pointers
   until the next loop iteration (~8 MB/min).

2. TrieDB hashdb growth: PendingBlockCommit inserts dirty trie nodes via
   state.Commit(), but RevertToBlockIndex never called Dereference() to
   release old state roots. Added Dereference on revert and Cap(16 MB)
   on commit as a safety net (~2 MB/min).

3. Fork-mode inflightRequests map: ClientPool.launchRequest never deleted
   completed entries from the map. Passed the request key through and
   added a deferred delete (unbounded growth).

Closes #811

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@anishnaik anishnaik merged commit fe834ec into master Mar 10, 2026
15 checks passed
@anishnaik anishnaik deleted the dev/memory-leak-hotfixes branch March 10, 2026 20:40
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.

1 participant