webview_go icon indicating copy to clipboard operation
webview_go copied to clipboard

Rare segfault when using eval in dispatch

Open Le0Developer opened this issue 3 months ago • 0 comments

I am encountering a segfault very inconsistently and rarely right after calling Evaluate in a Dispatch callback.

I have following code that gets run from a separate goroutine from the main thread which called webview.Run():

func (ui *UI) eval(code string) {
	if ui.app.options.Verbose {
		fmt.Println("Eval:", code)
	}
	ui.webview.Dispatch(func() {
		wui.webview.Eval(code)
	})
}

Sometimes this segfaults in the main thread:

Eval: {valid js code}
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x0 pc=0x102f9c1b0]

goroutine 1 [running, locked to thread]:
github.com/webview/webview_go._webviewDispatchGoCallback(0x5)
	/go/pkg/mod/github.com/webview/[email protected]/webview.go:217 +0x120
github.com/webview/webview_go._Cfunc_webview_run(0x6000012d8000)
	_cgo_gotypes.go:237 +0x30
github.com/webview/webview_go.(*webview).Run.func1(0x6000031e4900?)
	/go/pkg/mod/github.com/webview/[email protected]/webview.go:157 +0x40
github.com/webview/webview_go.(*webview).Run(0x1400019a0b0?)
	/go/pkg/mod/github.com/webview/[email protected]/webview.go:157 +0x1c
app/src.(*WebviewUII).run(0x1400019c1c8)
	app/src/ui_webview.go:40 +0x358
app/src/ui_webview.go:40 +0x358app/src.(*App).Run(0x140001e6180)
	app/src/app.go:41 +0x34
main.main()
	app/main.go:47 +0x4e0
exit status 2

The evaluate is triggered in response to a binding, it's basically:

webview.Bind("rpc", func() {
  go func() {
    app.ui.eval("rpcResponse(42)")
  }()
})

I wrote my own RPC wrapper on top of the one provided because some calls do network requests and thus need to be ran in a goroutine or it'd block the entire UI.

I've been able to reproduce this inconsistently on macOS (MBA, M2) and on Windows 10. The chance of this segfault is like 0.1%, I have never been able to cause it on purpose, only during normal usage.


Please let me know if you need any further information, or know any launch options I could use to gather more information.

Le0Developer avatar Mar 31 '24 10:03 Le0Developer