Fix memory leak in payloadAttributes map cleanup#778
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes a memory leak in the builder API service by ensuring stale payloadAttributes entries are actually deleted, and improves request-body resource cleanup for gzip-encoded submissions.
Changes:
- Fix
payloadAttributescleanup loop to delete by the actual map key rather than re-constructing an incorrect key. - Ensure the gzip reader is closed in
handleSubmitNewBlockso the underlying flate reader can be returned to its pool.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
803
to
807
| // Step 1: clean up old ones | ||
| for parentBlockHash, attr := range api.payloadAttributes { | ||
| for key, attr := range api.payloadAttributes { | ||
| if attr.slot < apiHeadSlot { | ||
| delete(api.payloadAttributes, getPayloadAttributesKey(parentBlockHash, attr.slot)) | ||
| delete(api.payloadAttributes, key) | ||
| } |
There was a problem hiding this comment.
Consider adding a regression test that exercises the cleanup path in processPayloadAttributes (i.e., seed api.payloadAttributes with an entry whose slot is < headSlot and verify it is removed). This change fixes a key-construction bug that would be easy to reintroduce without a focused test.
## Summary
- Fix payloadAttributes map entries never being deleted due to incorrect key construction in cleanup loop
- Close gzip reader in handleSubmitNewBlock to return flate decompressor to sync.Pool
## Motivation and Context
The builder API service exhibited a memory leak. The range variable in the cleanup loop held the full map key ("{parentHash}-{slot}"), but was passed to getPayloadAttributesKey which appended the slot again, producing a key that never matched any entry.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
d58b311 to
e99ad36
Compare
metachris
approved these changes
Feb 18, 2026
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
⛱ Motivation and Context
The builder API service exhibited a memory leak. The range variable in the cleanup loop held the full map key ("{parentHash}-{slot}"), but was passed to getPayloadAttributesKey which appended the slot again, producing a key that never matched any entry.
📚 References
✅ I have run these commands
make lintmake test-racego mod tidyCONTRIBUTING.md