wasmerio / wasmer-go

🐹🕸️ WebAssembly runtime for Go

Home Page:https://pkg.go.dev/github.com/wasmerio/wasmer-go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Wasmer instance gets garbage collected while still in use

nicolasmattelaer opened this issue · comments

Thanks for the bug report!

Describe the bug

If, after using a wasmer instance, the garbage collector runs, it sweeps the instance and causes the program to crash when calling wasm functions with a segmentation fault.

Steps to reproduce

  1. Running the example code at https://pkg.go.dev/github.com/wasmerio/wasmer-go/wasmer, but adding runtime.GC() right below the sum, err := instance.Exports.GetFunction("sum") line

Expected behavior

Program runs and finishes as normal

Actual behavior

You get a segmentation fault:

fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0x7f9d78702263 pc=0x7f9d78702263]

due to instance having been garbage collected.

Additional context

I suggest adding defer instance.Close() to the example at https://pkg.go.dev/github.com/wasmerio/wasmer-go/wasmer. This will prevent the bug but only because a reference to instance is kept, not because the instance.Close() function does anything to prevent it.