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

Memory leak in instance creation #148

Closed
koponen-styra opened this issue Nov 12, 2020 · 7 comments
Closed

Memory leak in instance creation #148

koponen-styra opened this issue Nov 12, 2020 · 7 comments
Assignees
Labels
🐞 bug Something isn't working
Milestone

Comments

@koponen-styra
Copy link
Contributor

koponen-styra commented Nov 12, 2020

Thanks for the bug report!

Describe the bug

Releasing the instance doesn't free all memory.

Steps to reproduce

  1. Run the following:

import (
        "github.com/wasmerio/wasmer-go/wasmer"
        "runtime"
)

func main() {
        for {
                instance()
        }
}

func instance() {
        wasmBytes := []byte(`
                (module
                  (type $add_one_t (func (param i32) (result i32)))
                  (func $add_one_f (type $add_one_t) (param $value i32) (result i32)
                    local.get $value
                    i32.const 1
                    i32.add)
                  (export "add_one" (func $add_one_f)))
        `)

        engine := wasmer.NewEngine()
        store := wasmer.NewStore(engine)
        module, err := wasmer.NewModule(store, wasmBytes)
        if err != nil {
                panic(err)
        }

        importObject := wasmer.NewImportObject()
        _, err = wasmer.NewInstance(module, importObject)
        if err != nil {
                panic(err)
        }

        runtime.GC()
} 
  1. See the process memory usage to increase and eventually the process crashing to "Cannot allocate memory".

Additional context:

Uncommenting the commented out SetFinalizer call (with TODO note) in import_object.go has no effect.

@koponen-styra koponen-styra added the 🐞 bug Something isn't working label Nov 12, 2020
@jubianchi jubianchi self-assigned this Nov 13, 2020
@jubianchi
Copy link
Contributor

Hi @koponen-styra, thanks for reporting this!

I can confirm the leak here.

We are currently looking at memory leaks on Wasmer. The one you are experiencing does not come from Go but from the Rust part.

@syrusakbary
Copy link
Member

Small update: we already have a quick fix for the memory leak and we are doing a deep research to find more!

wasmerio/wasmer#1822

@koponen-styra
Copy link
Contributor Author

Small update: we already have a quick fix for the memory leak and we are doing a deep research to find more!

wasmerio/wasmer#1822

Great!

@syrusakbary
Copy link
Member

We merged the mentioned PR, and now are solving a small leak when using exports in instances. It should be upstream soon!

@syrusakbary
Copy link
Member

We have a PR in progress that solves all the observed memory leaks:

wasmerio/wasmer#1837 (comment)

==92344== LEAK SUMMARY:
==92344==    definitely lost: 0 bytes in 0 blocks
==92344==    indirectly lost: 0 bytes in 0 blocks
==92344==      possibly lost: 0 bytes in 0 blocks
==92344==    still reachable: 68,961 bytes in 178 blocks
==92344==         suppressed: 15,633 bytes in 163 blocks

@jubianchi
Copy link
Contributor

Hi @koponen-styra!

Some updates here: beta1 of Wasmer is out and it fixes many (most of) the leaks.

The release for wasmer-go will follow shortly. If you want to give it a try before it's out, have a look at #153.

@jubianchi jubianchi added this to the 1.0.0 milestone Dec 4, 2020
@jubianchi
Copy link
Contributor

I'm closing this issue for now as our tests did not reveal any leak actually.

Feel free to reopen if needed.

@prep prep mentioned this issue May 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants