Skip to content

Fix memory leak in payloadAttributes map cleanup#778

Merged
ilyaluk merged 1 commit intomainfrom
ilya/fix-memory-leak-cleanup
Feb 18, 2026
Merged

Fix memory leak in payloadAttributes map cleanup#778
ilyaluk merged 1 commit intomainfrom
ilya/fix-memory-leak-cleanup

Conversation

@ilyaluk
Copy link
Copy Markdown
Collaborator

@ilyaluk ilyaluk commented Feb 18, 2026

📝 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.

📚 References


✅ I have run these commands

  • make lint
  • make test-race
  • go mod tidy
  • I have seen and agree to CONTRIBUTING.md

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 payloadAttributes cleanup loop to delete by the actual map key rather than re-constructing an incorrect key.
  • Ensure the gzip reader is closed in handleSubmitNewBlock so 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 thread services/api/service.go
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)
}
Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
## 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>
@ilyaluk ilyaluk force-pushed the ilya/fix-memory-leak-cleanup branch from d58b311 to e99ad36 Compare February 18, 2026 13:38
@ilyaluk ilyaluk merged commit ac861c9 into main Feb 18, 2026
5 checks passed
@ilyaluk ilyaluk deleted the ilya/fix-memory-leak-cleanup branch February 18, 2026 13:41
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.

3 participants