easegress
easegress copied to clipboard
The WASM code cannot run on MacOS system
Describe the bug On MacOS system running WebAssembly code in Easegress report following error whether using easegress-assemblyscript-sdk or easegress-go-sdk
thread '<unnamed>' panicked at 'called `Option::unwrap()` on a `None` value', crates/c-api/src/linker.rs:105:80
2022-07-12T10:23:37.039+08:00 ERROR wasmhost/wasmhost.go:331 recovered from wasm error: runtime error: invalid memory address or nil pointer dereference
2022-07-12T10:23:37.039+08:00 ERROR httpserver/mux.go:437 http-server: response is nil
To Reproduce Just following README.md doc instruction
OS Version Darwin 20.4.0 x86_64
Hi, thanks a lot for your issue. Unfortunately, we didn't reproduce your problem. But we do find some mistakes in our doc. And we will fix them now. Once these problems fixed, please try it again to see if it works. If it still not fix your problem, please provide us more information and details about how you use it.
@suchen-sci This error log line ERROR httpserver/mux.go:437 http-server: response is nil
can be easily reproduced:using Easegress v2.0.0 don't configure proxy filter,just handle logic and return response in Wasm code.
The bug may be caused by that the response object is nil and not created by default in wasm code, like this issue
Using following code and configuration:
package main
import (
"github.com/xmh19936688/easegress-go-sdk/easegress"
)
func init() {
easegress.RegisterProgramFactory(func(params map[string]string) easegress.Program {
program := &WasmDemo{}
program.Init(params)
return program
})
}
func main() {
}
type WasmDemo struct {
easegress.Program
}
func (program *WasmDemo) Init(params map[string]string) {
}
func (program *WasmDemo) Run() int32 {
easegress.RespSetStatusCode(200)
easegress.RespSetBody([]byte("OK"))
return 0
}
tinygo build -o wasm-demo.wasm -target wasi ./
cat <<EOF | egctl object create
kind: HTTPServer
name: http-server
port: 10080
keepAlive: true
https: false
rules:
- paths:
- pathPrefix: /wasm-demo
backend: wasm-demo-pipeline
---
name: wasm-demo-pipeline
kind: Pipeline
flow:
- filter: wasm
filters:
- name: wasm
kind: WasmHost
code: wasm-demo.wasm # Here add your local absolute path
EOF
curl http://localhost:10080/wasm-demo -v
@jthann , the behavior has been changed because v2.0 does not have a default response. We can now use a ResponseBuilder before the WasmHost to create the response as a workaround. We will enhance the WasmHost filter to make it able to access requests/responses in any namespace later.
It work out okay after adding ResponseBuilder filter
name: wasm-demo-pipeline
kind: Pipeline
flow:
- filter: respBuilder
- filter: wasm
filters:
- name: respBuilder
kind: ResponseBuilder
template: |
statusCode: 200
- name: wasm
kind: WasmHost
code: wasm-demo.wasm