Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

headerdownload: fix OOM due to inifinitely growing children in link #12404

Merged
merged 1 commit into from
Oct 22, 2024

Conversation

taratorio
Copy link
Member

@taratorio taratorio commented Oct 21, 2024

relates to #11387, #11473, #10734

tried to simulate the OOM using #11799

What I found was infinitely growing alloc of headers when receiving new header messages in sentry's blockHeaders66 handler (check screenshot below).

It looks like this is happening because in the case of a bad child header: we delete it from the links map, however its parent link still holds a reference to it so the deleted link & header never get gc-ed. Furthermore if new similar bad hashes arrive after deletion they get appended to their parent header's link and the children of that link can grow indefinitely (here). Ie confirmed with debug logs (note link at 13450415 has 140124 children):

DBUG[10-21|18:18:05.003] [downloader] InsertHeader: Rejected header parent info hash=0xb488d67deaf4103880fa972fd72a7a9be552e3bc653f124f1ad9cb45f36bcd07 height=13450415 children=140124

The solution for this is to remove the bad link from its parent child list here so that 1) it gets gc-ed and 2) the children list does not grow indefinitely.


oom-heap-profile2

@@ -535,8 +540,6 @@ func (hd *HeaderDownload) InsertHeader(hf FeedHeaderFunc, terminalTotalDifficult
}
if bad {
// If the link or its parent is marked bad, throw it out
hd.moveLinkToQueue(link, NoQueue)
delete(hd.links, link.hash)
Copy link
Member Author

@taratorio taratorio Oct 21, 2024

Choose a reason for hiding this comment

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

done already inside hd.removeUpwards(link)

hd.removeUpwards(link)
if parentLink, ok := hd.links[link.header.ParentHash]; ok {
parentLink.RemoveChild(link)
}
Copy link
Member Author

Choose a reason for hiding this comment

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

done already inside hd.removeUpwards(link)

@AskAlexSharov AskAlexSharov merged commit 5e62f1d into main Oct 22, 2024
11 checks passed
@AskAlexSharov AskAlexSharov deleted the stage-headers-fix-oom branch October 22, 2024 05:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants