Open
Conversation
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.
I use wasmtime to host a long lived wasip1 program, and I discovered a memory leak.
The issue is in async wasip1 contexts. The minimal code to reproduce (is taken from the existing
wasip1-asyncexample):As well as a minimal wasm program:
Now, running the program in heaptrack with
heaptrack ./target/release/examples/wasip1-async, we can see that there is a problem:It grows by megabytes in minutes.
The issue was in
wasmtime_wasi::p2::host::clocks::subscribe_to_duration(and an underlying Vec grow). If I understand correctly, wasip1 is implemented in terms of wasip2. Wasip2 creates pollables and hands them off to a guest app, but the wasip1 code was just creating pollables and never dropping them. So to fix it, I just drop those pollables after we are done using them. Also, I added code to drop the partial pollable list if it encounters an error while still creating more pollables.And here is a screenshot of heaptrack on my fix branch, after :
Perfectly flat, even after a long time!
I was not able to find an open issue about this, so I just made this PR. Let me know if this fix is sensible or what I can do to make it more robust.