spinframework / spinframework/spin
Logging fails on TinyGo Spin Apps
Open
Nobody has claimed this yet.
bug
- Dominant language
- Rust
- Stars
- 6.5k
- Forks
- 310
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 24
Description
Problem:
TinyGo Spin apps that use log gets the following runtime error from Wasmtime:
$ spin build --up
Building component go-app with `tinygo build -target=wasi -gc=leaking -no-debug -o main.wasm main.go`
Finished building all Spin components
Logging component stdio to ".spin/logs/"
Serving http://127.0.0.1:3000
Available Routes:
go-app: http://127.0.0.1:3000 (wildcard)
panic: runtime error: nil pointer dereference
2023-12-15T23:25:33.689230Z ERROR spin_trigger_http: Error processing request: error while executing at wasm backtrace:
0: 0xeb05 - <unknown>!runtime.runtimePanicAt.llvm.3901647063377195771
1: 0x33a77 - <unknown>!byn$mgfn-shared$runtime.lookupPanic.llvm.3901647063377195771
2: 0x574a - <unknown>!runtime.nilPanic.llvm.3901647063377195771
3: 0xcfe7 - <unknown>!(*sync.Mutex).Lock
4: 0x32ca5 - <unknown>!spin_http_handle_http_request
5: 0x33870 - <unknown>!__wasm_export_spin_http_handle_http_request
6: 0x441b8 - wit-component:adapter:wasi_snapshot_preview1!fermyon:spin/inbound-http#handle-request
Caused by:
wasm trap: wasm `unreachable` instruction executed
Example app:
package main
import (
"fmt"
"log"
"net/http"
spinhttp "github.com/fermyon/spin/sdk/go/v2/http"
)
func init() {
spinhttp.Handle(func(w http.ResponseWriter, r *http.Request) {
log.Printf("THIS WILL CAUSE AN ERROR")
fmt.Fprintln(w, "== THIS WILL NOT BE REACHED ==")
})
}
func main() {}
- Spin version (
spin --version)
spin 2.0.1 (1d72f1c 2023-11-10)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the example app with spin build --up and the pinned Spin version, then trace the log.Printf path through TinyGo, WASI, and Wasmtime. Done means the request completes without the nil pointer dereference, the log is emitted successfully, and the response reaches the client.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, wasm
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100