[hermes] Fix memory leak #881
Merged
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.
@thmzlt identified a memory leak in our edge deployment. @Reisen and I worked on investigating it. We had an initial suspicion about libp2p because price service also apparently has a memory leak. Because of that in #876 we added go profiler to hermes. However, after more investigations, we realized that in price-service the node part has a leak and then it is probably not the libp2p and it's our code.
@Reisen suggested using heaptrack to profile the heap and I created a separate image with heaptrack and deployed it in the cluster. Using
heaptrack_print(the cli tool) we can get the peak memory usages and after analyzing the logs over time I realized that the memory usages of this part of the code is increasing:And then we checked our proxy method for communicating with go and found the issue. The issue was that apparently the go caller of our proxy method doesn't free the input that it passes to the method because the defer in a loop runs after the loop is over. I ran the fix for a couple of hours and the heap grow from this call stopped.