wasmer-go: Error: UnableToCreateMemory

Summary

When I iteratively create an instance of a module and then close it, I get an UnableToCreateMemory error.

Additional details

Here is the code I’m running:

package main

import (
	"fmt"
	wasm "github.com/wasmerio/go-ext-wasm/wasmer"
)

func main() {
	bytes, err := wasm.ReadBytes("./simple.wasm")
	if err != nil { panic(err) }

	module, err := wasm.Compile(bytes)
	if err != nil { panic(err) }
	defer module.Close()

	for i:=0; i<1000000; i++ {
		fmt.Println(i)

		instance, err := module.Instantiate()
		if err != nil { panic(err) }
		instance.Close()
	}
}

For reference, here is the body of the simple.wasm file in base64 encoding, but I’d assume the results will be similar with any wasm binary.

AGFzbQEAAAABBwFgAn9/AX8DAgEABAUBcAEBAQUDAQAQBhECfwBBgIDAAAt/AEGAgMAACwdHBQZtZW1vcnkCABlfX2luZGlyZWN0X2Z1bmN0aW9uX3RhYmxlAQALX19oZWFwX2Jhc2UDAApfX2RhdGFfZW5kAwEDc3VtAAAJAQAKCQEHACAAIAFqCw==

Here is the tail of the output that I get:

32723
32724
32725
32726
panic: Failed to instantiate the module:
    link error: unable to create memory: UnableToCreateMemory

goroutine 1 [running]:
main.main()
	/demo/src/hello/hello.go:20 +0x250
exit status 2

The iteration count at which it fails (the last printed number) is non-deterministic, it varies a bit between re-runs.

I must be doing something wrong, can you help find the issue?

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 32 (12 by maintainers)

Most upvoted comments

I’ll give a try to reproduce the error!

Hi @Hywan, thanks for looking into this once more. That is so strange - I seem unable not to reproduce the issue. Did you run the test on OS-es running within a VM? I can still give you access to a cloud instance, if you want - I am currently on Wasmer slack, so I could chat with you there - or I could just e-mail you login info.

Another option would be to think about what might be different between your setup and @zupa-hu and my setup. Or what we might do differently from you - we are doing clean installs like this:

https://github.com/wasmerio/go-ext-wasm/issues/82#issuecomment-557837451

Hi @Hywan , we currently encounter the exact same issue in several of our Wasmer based projects.

@zupa-hu isolates the problem nicely with his example code:

package main

import (
	"fmt"
	"encoding/base64"
	wasm "github.com/wasmerio/go-ext-wasm/wasmer"
)

const WASM_BINARY_BASE64 = `
AGFzbQEAAAABBwFgAn9/AX8DAgEABAUBcAEBAQUDAQAQBhECfwBBgIDAAAt/AEGAgMAACw
dHBQZtZW1vcnkCABlfX2luZGlyZWN0X2Z1bmN0aW9uX3RhYmxlAQALX19oZWFwX2Jhc2UD
AApfX2RhdGFfZW5kAwEDc3VtAAAJAQAKCQEHACAAIAFqCw==
`

func main() {
	bytes, err := base64.StdEncoding.DecodeString(WASM_BINARY_BASE64)
	if err != nil { panic(err) }

	module, err := wasm.Compile(bytes)
	if err != nil { panic(err) }
	defer module.Close()

	for i:=0; i<1000000; i++ {
		fmt.Println(i)

		instance, err := module.Instantiate()
		if err != nil { panic(err) }
		instance.Close()
	}
}

I was able to reproduce the issue on my dev laptop Ubunbu WSL vm, and using three separate Hetzner cloud server instances: a clean Ubuntu 18.04, a Debian 4.19.98-1, and a Fedora 31 based image.

Installed the latest go and the latest go-ext-wasmer on each (clean and up to date) instance (using go get github.com/wasmerio/go-ext-wasm/wasmer).

Each machine gives the exact same result:

...
32717
32718
32719
32720
32721
32722
32723
32724
32725
32726
panic: Failed to instantiate the module:
    link error: unable to create memory: UnableToCreateMemory

goroutine 1 [running]:
main.main()
	/root/goProject/test.go:27 +0x24c
exit status 2

Would be super if you would be able to help us out with this issue!

Thanks for running it. I’ll try on bare metal. VirtualBox is the only common element between the 2 systems on which I tested. (Well, the only one I can think of.) Will get back on this.

Contact me on Slack. We will try to investigate on this. I don’t like having an unreproducible bug. Thanks for your patience!

I tried with macOS, Ubuntu and Debian (amd64 every time), with no success 😕.

Just wanted to add that I’m also super keen on getting this worked out.

Thanks @robinvanemden on your input. Your suggestion with the cloud server instance is superb. @Hywan, if you could try to install it there, then we will either have a working setup or you would have a means to reproduce it. Progress either way. I really hope you can give it a go.

If you want, I can give you access to a clean cloud server instance - just ping me at rss@pwy.nl - or currently at Wasmer’s slack 😃

I’m sorry but I still can’t reproduce your error 😕. I don’t know how I can help you… Can you tell me what’s your OS and arch please?