Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rare segfault when using eval in dispatch #39

Open
Le0Developer opened this issue Mar 31, 2024 · 0 comments
Open

Rare segfault when using eval in dispatch #39

Le0Developer opened this issue Mar 31, 2024 · 0 comments

Comments

@Le0Developer
Copy link

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/webview_go@v0.0.0-20230901181450-5a14030a9070/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/webview_go@v0.0.0-20230901181450-5a14030a9070/webview.go:157 +0x40
github.com/webview/webview_go.(*webview).Run(0x1400019a0b0?)
	/go/pkg/mod/github.com/webview/webview_go@v0.0.0-20230901181450-5a14030a9070/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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant