Skip to content

Memory not released for WASI resources #152

@teebee64

Description

@teebee64

I'm experiencing continuous memory growth when running a long-lived Python WebAssembly component compiled using componentize-py and executed via wasmtime.

Any time a wasi resource is created (e.g. a Fields resource from wasi-http or any other wasi resource), the resource appears to stay in memory after it goes out of scope. This is in contrast to typical Python objects (like lists or dictionaries) which are correctly garbage-collected.

In my application i have implemented a Server-Sent Events (SSE) client that continuously reads data from an InputStream resource from wasi-io. Each time the read function is executed, the data that has been read also stays in memory. So over time, as the SSE client keeps receiving data, the memory keeps increasing until a MemoryError is received.

Here's the relevant code snippet:

incomingBody: wasi_http_types.IncomingBody = self._response.consume()
with incomingBody:
    inputStream: streams.InputStream = incomingBody.stream()
    with inputStream:
        while True:
            try:
                pollable: poll.Pollable = inputStream.subscribe()
                with pollable: 
                    pollable.block()
                    chunk: bytes = inputStream.read(chunk_size) # All data read here is kept in memory and does not get released
                    yield chunk
            except ...

Is this a bug, or am I missing something in how these resources should be managed?

Thanks in advance for any help!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions