Fixed the memory leak/coverage processing issue#74
Merged
thatjiaozi merged 2 commits intogoogle:mainfrom Jun 16, 2025
Merged
Conversation
thatjiaozi
approved these changes
Jun 16, 2025
Collaborator
thatjiaozi
left a comment
There was a problem hiding this comment.
Hey!
Thanks for taking the time to track and fix this. And sorry for the delay of the review!
Approving and merging changes.
Collaborator
|
Apologies, the build is broken due to an issue unrelated to your PR. I am fixing it in #75 and then merging your changes |
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.
This change introduces a fix for issue #62 as well as coverage reporting issue that I encountered while running buzzer on an ARM CPU.
Collected coverage information is getting pushed to a queue, which was processed asynchronously by a separate thread. The coverage addresses are being piped to addr2line utility which returns line numbers. After some profiling, it turns out that this coverage info queue was never drained.
The issue lies in how the call to addr2line utility is made. The exec.Command() call is set up with a list of memory addresses separated by newline chars is being written to the stdin pipe. The problem was caused by the fact that the execution of the program is only kicked off by cmd.Output() call, however the write to the pipe is a blocking call. With large enough input (which appears to be 8k on my system), the pipe runs out of the buffer and blocks further writes awaiting for addr2line to consume some input. Since addr2line is not running at this point, coverage processing is stuck forever.
This results in the coverage queue filling up fast, resulting in eventual OOM crash.
The solution is to move the write call to a separate goroutine to make this a non blocking operation. This will allow the execution to start without waiting for the write to finish. Once write is done, stdin pipe will be closed, which will result in addr2line exiting once it reaches the end of input and cmd.Output() returning the results.