knqyf263 / go-plugin

Go Plugin System over WebAssembly
MIT License
578 stars 27 forks source link

After update: panic: free: invalid pointer #46

Closed inliquid closed 1 year ago

inliquid commented 1 year ago

I just updated my code snippets to latest go-plugin and wazero, and I start seeing this message in host stdout:

panic: free: invalid pointer

It seems it does not affect the logic, just says that something bad (?) happened?

It's with "Cat" example which outputs the contents of a host file by reading it from guest.

I suspect that's because of this change to autogenerated stubs:

    // We don't need the memory after deserialization: make sure it is freed.
    if resPtr != 0 {
        defer p.free.Call(ctx, uint64(resPtr))
    }
dmvolod commented 1 year ago

What is your operating system? As tests utilizing plain stdout output for validation, this case nevet been passed in case of panic in host stdout. But others operating systems except Linux never been tested for plugin in periodic manner.

inliquid commented 1 year ago

Just tested both on:

And got exact same result.

Just in case, this is how plugin is being initialized:

    mc := wazero.NewModuleConfig().WithStdout(os.Stdout).WithStderr(os.Stderr).WithFS(fs)

    p, err := api.NewGreeterPlugin(ctx, api.WazeroModuleConfig(mc))
    if err != nil {
        panic(err)
    }
dmvolod commented 1 year ago

I've reproduced your behavior. It seems plugin code didn't recompiled as both wasm/host have code been changed in last commit https://github.com/knqyf263/go-plugin/commit/9341dcbdcdc65152658b7d84bb96ae7642e9b4f7#diff-0e6c67cd1f316a92a15c89ebaed80e7e68c19cfbc62bf64ffe3262bc058e0e2c

File loading...
panic: free: invalid pointer
Hello WASI!
inliquid commented 1 year ago

Sorry I don't quite get, I for sure recompiled protoc plugin with:

go install github.com/knqyf263/go-plugin/cmd/protoc-gen-go-plugin@main

Note that I took code from main, not latest, so it has most recent changes.

Is this what you mean?

inliquid commented 1 year ago

Ok, I retried with latest instead of main and error disappeared. Is this what I supposed to do?

I switched to using main because there was some case where I had to.

dmvolod commented 1 year ago

Yes, sure. Good to know :+1:

inliquid commented 1 year ago

Thanks, closing.