v2/examples/panic-recovery-test/README.md
This example demonstrates the Linux signal handler issue (#3965) and verifies the fix using runtime.ResetSignalHandlers().
On Linux, WebKit installs signal handlers without the SA_ONSTACK flag, which prevents Go from recovering panics caused by nil pointer dereferences (SIGSEGV). Without the fix, the application crashes with:
signal 11 received but handler not on signal stack
fatal error: non-Go code set up signal handler without SA_ONSTACK flag
Call runtime.ResetSignalHandlers() immediately before code that might panic:
import "github.com/wailsapp/wails/v2/pkg/runtime"
go func() {
defer func() {
if err := recover(); err != nil {
log.Printf("Recovered: %v", err)
}
}()
runtime.ResetSignalHandlers()
// Code that might panic...
}()
Build the example:
cd v2/examples/panic-recovery-test
wails build -tags webkit2_41
Run the application:
./build/bin/panic-recovery-test
Wait ~10 seconds (the app auto-calls Greet after 5s, then waits another 5s before the nil pointer dereference)
The panic is recovered and you see:
------------------------------"invalid memory address or nil pointer dereference"
The application continues running.
Comment out the runtime.ResetSignalHandlers() call in app.go and rebuild. The application will crash with a fatal signal 11 error.
app.go - Contains the Greet function that demonstrates panic recoveryfrontend/src/main.js - Auto-calls Greet after 5 seconds to trigger the test