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

fatal error: non-Go code set up signal handler without SA_ONSTACK flag #2134

Closed
mholt opened this issue Nov 27, 2022 · 16 comments · Fixed by #2152
Closed

fatal error: non-Go code set up signal handler without SA_ONSTACK flag #2134

mholt opened this issue Nov 27, 2022 · 16 comments · Fixed by #2152
Labels
Bug Something isn't working

Comments

@mholt
Copy link
Contributor

mholt commented Nov 27, 2022

Description

First off, I'm not sure if this is a bug in Wails. It could totally be in my own app! However, I'm not using cgo in my code or my go.mod dependencies (edit: except for sqlite, but that's not new -- and I've never seen this before until using Wails).

This is a similar to #1570, but I'm not using gRPC at all.

My program was running under wails dev, and while I wasn't interacting with it, it crashed:

signal 11 received but handler not on signal stack
fatal error: non-Go code set up signal handler without SA_ONSTACK flag

runtime stack:
runtime.throw({0x2330cad?, 0xc00009c000?})
        /usr/local/go/src/runtime/panic.go:1047 +0x5d fp=0xc000763618 sp=0xc0007635e8 pc=0x44dbfd
runtime.sigNotOnStack(0xb)
        /usr/local/go/src/runtime/signal_unix.go:1020 +0x65 fp=0xc000763638 sp=0xc000763618 pc=0x465305
runtime.adjustSignalStack(0xb, 0xc000780000, 0xc?)
        /usr/local/go/src/runtime/signal_unix.go:581 +0x156 fp=0xc000763698 sp=0xc000763638 pc=0x464156
runtime.sigtrampgo(0xb, 0xc0007639b0, 0xc000763880)
        /usr/local/go/src/runtime/signal_unix.go:469 +0x13b fp=0xc000763710 sp=0xc000763698 pc=0x463e3b
runtime.sigtramp()
        /usr/local/go/src/runtime/sys_linux_amd64.s:359 +0x46 fp=0xc000763760 sp=0xc000763710 pc=0x484b46

goroutine 17 [syscall, locked to thread]:
runtime.goexit()
        /usr/local/go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc0000aafe8 sp=0xc0000aafe0 pc=0x482ea1

goroutine 1 [syscall, 7 minutes, locked to thread]:
runtime.cgocall(0x1f2b240, 0xc0006b5b08)
        /usr/local/go/src/runtime/cgocall.go:158 +0x5c fp=0xc0006b5ae0 sp=0xc0006b5aa8 pc=0x41149c
github.com/wailsapp/wails/v2/internal/frontend/desktop/linux._Cfunc_gtk_main()
        _cgo_gotypes.go:1068 +0x45 fp=0xc0006b5b08 sp=0xc0006b5ae0 pc=0xd21f65
github.com/wailsapp/wails/v2/internal/frontend/desktop/linux.(*Frontend).RunMainLoop(0xc000b89c80)
        /home/matt/go/pkg/mod/github.com/wailsapp/wails/v2@v2.2.0/internal/frontend/desktop/linux/frontend.go:57 +0x1c fp=0xc0006b5b18 sp=0xc0006b5b08 pc=0xd2499c
github.com/wailsapp/wails/v2/internal/frontend/devserver.(*DevWebServer).RunMainLoop(0xc000187ef0)
        <autogenerated>:1 +0x34 fp=0xc0006b5b30 sp=0xc0006b5b18 pc=0xe03514
github.com/wailsapp/wails/v2/internal/app.(*App).Run(0xc000586780)
        /home/matt/go/pkg/mod/github.com/wailsapp/wails/v2@v2.2.0/internal/app/app_dev.go:30 +0x72 fp=0xc0006b5b98 sp=0xc0006b5b30 pc=0xe0ddf2
github.com/wailsapp/wails/v2/pkg/application.(*Application).Run(0xc00028dbc0)
        /home/matt/go/pkg/mod/github.com/wailsapp/wails/v2@v2.2.0/pkg/application/application.go:69 +0x169 fp=0xc0006b5c10 sp=0xc0006b5b98 pc=0xe10bc9
github.com/wailsapp/wails/v2.Run(0xc000164d80)
        /home/matt/go/pkg/mod/github.com/wailsapp/wails/v2@v2.2.0/wails.go:14 +0x33 fp=0xc0006b5c50 sp=0xc0006b5c10 pc=0xe10d53
.
.
.

Full stack trace is 700 lines. Let me know if you want me to provide it.

When this happened, my program did stop, but the CLI command kept running. I had to send it a signal to stop wails dev:

^C
Caught quit
Development mode exited

If Wails is useful to you or your company, please consider sponsoring the project:
https://github.com/sponsors/leaanthony

To Reproduce

Sadly, I don't know how to reproduce this. It has only happened this one time, and it is not the first time I have run these exact same functions on the exact same inputs. If it happens again I will let you know...

UPDATE: Put this right inside main():

go func() {
	time.Sleep(5 * time.Second)
	var t *time.Time
	log.Println(t.Unix())
}()

Expected behaviour

Not crash :)

Screenshots

No response

Attempted Fixes

No response

System Details

$ wails doctor
Wails CLI v2.2.0

Scanning system - Please wait (this may take a long time)...Done.

System
------
OS:             Pop!_OS
Version:        22.04
ID:             pop
Go Version:     go1.19.1
Platform:       linux
Architecture:   amd64

Wails
------
Version:                v2.2.0
Package Manager:        apt

Dependency      Package Name            Status          Version
----------      ------------            ------          -------
*docker         docker.io               Available       20.10.12-0ubuntu4
gcc             build-essential         Installed       11.3.0
libgtk-3        libgtk-3-dev            Installed       3.24.33-1ubuntu2
libwebkit       libwebkit2gtk-4.0-dev   Installed       2.38.2-0ubuntu0.22.04.2
npm             npm                     Installed       8.5.1~ds-1
*nsis           nsis                    Available       3.08-2
pkg-config      pkg-config              Installed       0.29.2

* - Optional Dependency

Diagnosis
---------
Your system is ready for Wails development!
Optional package(s) installation details: 
  - docker: sudo apt install docker.io
  - nsis: sudo apt install nsis



If Wails is useful to you or your company, please consider sponsoring the project:
https://github.com/sponsors/leaanthony

Additional context

Sorry this isn't the most helpful report. Let me know if you need more info!

@mholt mholt added the Bug Something isn't working label Nov 27, 2022
@leaanthony
Copy link
Member

leaanthony commented Nov 27, 2022

This is usually because 2 signal handlers have been installed. Does this help? https://stackoverflow.com/questions/73724723/libfuzzer-go-executable-crashes-with-non-go-code-set-up-signal-handler-without

More insight into it happening with libreoffice: https://bugs.documentfoundation.org/show_bug.cgi?id=140189

So sounds like some third party lib is setting up a signal handler that's incompatible with Go's signal handling.

@mholt
Copy link
Contributor Author

mholt commented Nov 27, 2022

Thanks, that's interesting! Maybe my program is segfaulting (nil pointer dereference, I'd bet) but something is eating the segfault and not showing the error, so I'm not sure how to debug it.

Hmm, so I have one in my program:

sigchan := make(chan os.Signal, 1)
signal.Notify(sigchan, syscall.SIGTERM, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGUSR1, syscall.SIGUSR2)

But nothing else I import does this, as far as I can tell.

Could the third-party lib potentially be something in Wails? (with the dev build tag set from wails dev)?

(I ran this code for months before using Wails, and never experienced this error. Haven't added other new dependencies since then.)

@leaanthony
Copy link
Member

leaanthony commented Nov 27, 2022

I believe multiple signal handlers within Go are just fine. The SA_STACK issue appears to be very specific: it's when a signal handler is created in C without the SA_STACK flag and then a signal is triggered by whatever means. I believe it's extremely unlikely (but not impossible) that it's within a Wails dependency on Linux as we've only had this reported once before in the history of the project. I'd fully expect this to be a common issue on GitHub if it was in gtk or WebKit. I'm going to do some due diligence around scanning the WebKit and gtk code though to check their signal handlers.

What does ldd show for you?

@mholt
Copy link
Contributor Author

mholt commented Nov 27, 2022

I can reproduce it!! Right inside main():

go func() {
	time.Sleep(5 * time.Second)
	var t *time.Time
	log.Println(t.Unix())
}()

Obviously, this is a nil pointer dereference. And sure enough, the same signal 11 received but handler not on signal stack\nfatal error: non-Go code set up signal handler without SA_ONSTACK flag error appears at this exact moment.

So, I think what is happening is my code is panicking (oops) but I can't know where (oops) because of some cgo interaction.

Here's the output of ldd on the binary from wails build (it happens with that binary too):

        linux-vdso.so.1 (0x00007ffd33571000)
        libwebkit2gtk-4.0.so.37 => /lib/x86_64-linux-gnu/libwebkit2gtk-4.0.so.37 (0x00007f4683a00000)
        libgtk-3.so.0 => /lib/x86_64-linux-gnu/libgtk-3.so.0 (0x00007f4683000000)
        libgdk-3.so.0 => /lib/x86_64-linux-gnu/libgdk-3.so.0 (0x00007f4687814000)
        libgdk_pixbuf-2.0.so.0 => /lib/x86_64-linux-gnu/libgdk_pixbuf-2.0.so.0 (0x00007f46839d0000)
        libgio-2.0.so.0 => /lib/x86_64-linux-gnu/libgio-2.0.so.0 (0x00007f4682e28000)
        libjavascriptcoregtk-4.0.so.18 => /lib/x86_64-linux-gnu/libjavascriptcoregtk-4.0.so.18 (0x00007f4681600000)
        libgobject-2.0.so.0 => /lib/x86_64-linux-gnu/libgobject-2.0.so.0 (0x00007f4683970000)
        libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007f4683836000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f4681200000)
        libEGL.so.1 => /lib/x86_64-linux-gnu/libEGL.so.1 (0x00007f46877ff000)
        libicui18n.so.70 => /lib/x86_64-linux-gnu/libicui18n.so.70 (0x00007f4680e00000)
        libicuuc.so.70 => /lib/x86_64-linux-gnu/libicuuc.so.70 (0x00007f4680c05000)
        libsystemd.so.0 => /lib/x86_64-linux-gnu/libsystemd.so.0 (0x00007f4681539000)
        libpango-1.0.so.0 => /lib/x86_64-linux-gnu/libpango-1.0.so.0 (0x00007f46814d2000)
        libharfbuzz.so.0 => /lib/x86_64-linux-gnu/libharfbuzz.so.0 (0x00007f4681131000)
        libatk-1.0.so.0 => /lib/x86_64-linux-gnu/libatk-1.0.so.0 (0x00007f46814a8000)
        libcairo.so.2 => /lib/x86_64-linux-gnu/libcairo.so.2 (0x00007f4680add000)
        libxml2.so.2 => /lib/x86_64-linux-gnu/libxml2.so.2 (0x00007f46808fb000)
        libsqlite3.so.0 => /lib/x86_64-linux-gnu/libsqlite3.so.0 (0x00007f46807ae000)
        libxslt.so.1 => /lib/x86_64-linux-gnu/libxslt.so.1 (0x00007f4681466000)
        libOpenGL.so.0 => /lib/x86_64-linux-gnu/libOpenGL.so.0 (0x00007f468143a000)
        libGLX.so.0 => /lib/x86_64-linux-gnu/libGLX.so.0 (0x00007f468077a000)
        liblcms2.so.2 => /lib/x86_64-linux-gnu/liblcms2.so.2 (0x00007f4680718000)
        libwoff2dec.so.1.0.2 => /lib/x86_64-linux-gnu/libwoff2dec.so.1.0.2 (0x00007f4682e1c000)
        libfontconfig.so.1 => /lib/x86_64-linux-gnu/libfontconfig.so.1 (0x00007f46806ce000)
        libfreetype.so.6 => /lib/x86_64-linux-gnu/libfreetype.so.6 (0x00007f4680606000)
        libharfbuzz-icu.so.0 => /lib/x86_64-linux-gnu/libharfbuzz-icu.so.0 (0x00007f468382f000)
        libgcrypt.so.20 => /lib/x86_64-linux-gnu/libgcrypt.so.20 (0x00007f46804c8000)
        libgstapp-1.0.so.0 => /lib/x86_64-linux-gnu/libgstapp-1.0.so.0 (0x00007f46804b2000)
        libgstbase-1.0.so.0 => /lib/x86_64-linux-gnu/libgstbase-1.0.so.0 (0x00007f468042d000)
        libgstreamer-1.0.so.0 => /lib/x86_64-linux-gnu/libgstreamer-1.0.so.0 (0x00007f46802dc000)
        libgstpbutils-1.0.so.0 => /lib/x86_64-linux-gnu/libgstpbutils-1.0.so.0 (0x00007f4680298000)
        libgstaudio-1.0.so.0 => /lib/x86_64-linux-gnu/libgstaudio-1.0.so.0 (0x00007f4680216000)
        libgsttag-1.0.so.0 => /lib/x86_64-linux-gnu/libgsttag-1.0.so.0 (0x00007f46801d4000)
        libgstvideo-1.0.so.0 => /lib/x86_64-linux-gnu/libgstvideo-1.0.so.0 (0x00007f468010f000)
        libgstgl-1.0.so.0 => /lib/x86_64-linux-gnu/libgstgl-1.0.so.0 (0x00007f4680087000)
        libgstfft-1.0.so.0 => /lib/x86_64-linux-gnu/libgstfft-1.0.so.0 (0x00007f4682e10000)
        libjpeg.so.8 => /lib/x86_64-linux-gnu/libjpeg.so.8 (0x00007f4680006000)
        libpng16.so.16 => /lib/x86_64-linux-gnu/libpng16.so.16 (0x00007f467ffcb000)
        libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f467ffaf000)
        libopenjp2.so.7 => /lib/x86_64-linux-gnu/libopenjp2.so.7 (0x00007f467ff57000)
        libwebpdemux.so.2 => /lib/x86_64-linux-gnu/libwebpdemux.so.2 (0x00007f4681434000)
        libwebp.so.7 => /lib/x86_64-linux-gnu/libwebp.so.7 (0x00007f467feeb000)
        libsoup-2.4.so.1 => /lib/x86_64-linux-gnu/libsoup-2.4.so.1 (0x00007f467fe4e000)
        libenchant-2.so.2 => /lib/x86_64-linux-gnu/libenchant-2.so.2 (0x00007f467fe40000)
        libgmodule-2.0.so.0 => /lib/x86_64-linux-gnu/libgmodule-2.0.so.0 (0x00007f468142d000)
        libsecret-1.so.0 => /lib/x86_64-linux-gnu/libsecret-1.so.0 (0x00007f467fdde000)
        libtasn1.so.6 => /lib/x86_64-linux-gnu/libtasn1.so.6 (0x00007f467fdc6000)
        libhyphen.so.0 => /lib/x86_64-linux-gnu/libhyphen.so.0 (0x00007f467fdbf000)
        libX11.so.6 => /lib/x86_64-linux-gnu/libX11.so.6 (0x00007f467fc7f000)
        libXcomposite.so.1 => /lib/x86_64-linux-gnu/libXcomposite.so.1 (0x00007f467fc7a000)
        libXdamage.so.1 => /lib/x86_64-linux-gnu/libXdamage.so.1 (0x00007f467fc75000)
        libwayland-server.so.0 => /lib/x86_64-linux-gnu/libwayland-server.so.0 (0x00007f467fc5f000)
        libwayland-egl.so.1 => /lib/x86_64-linux-gnu/libwayland-egl.so.1 (0x00007f467fc5a000)
        libwayland-client.so.0 => /lib/x86_64-linux-gnu/libwayland-client.so.0 (0x00007f467fc49000)
        libmanette-0.2.so.0 => /lib/x86_64-linux-gnu/libmanette-0.2.so.0 (0x00007f467fc19000)
        libseccomp.so.2 => /lib/x86_64-linux-gnu/libseccomp.so.2 (0x00007f467fbf9000)
        libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f467f800000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f467fb12000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f467faf2000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f4687934000)
        libpangocairo-1.0.so.0 => /lib/x86_64-linux-gnu/libpangocairo-1.0.so.0 (0x00007f467fae0000)
        libXi.so.6 => /lib/x86_64-linux-gnu/libXi.so.6 (0x00007f467facc000)
        libXfixes.so.3 => /lib/x86_64-linux-gnu/libXfixes.so.3 (0x00007f467fac4000)
        libcairo-gobject.so.2 => /lib/x86_64-linux-gnu/libcairo-gobject.so.2 (0x00007f467fab8000)
        libatk-bridge-2.0.so.0 => /lib/x86_64-linux-gnu/libatk-bridge-2.0.so.0 (0x00007f467fa7e000)
        libepoxy.so.0 => /lib/x86_64-linux-gnu/libepoxy.so.0 (0x00007f467f6cb000)
        libfribidi.so.0 => /lib/x86_64-linux-gnu/libfribidi.so.0 (0x00007f467fa62000)
        libpangoft2-1.0.so.0 => /lib/x86_64-linux-gnu/libpangoft2-1.0.so.0 (0x00007f467fa47000)
        libXinerama.so.1 => /lib/x86_64-linux-gnu/libXinerama.so.1 (0x00007f467fa42000)
        libXrandr.so.2 => /lib/x86_64-linux-gnu/libXrandr.so.2 (0x00007f467fa33000)
        libXcursor.so.1 => /lib/x86_64-linux-gnu/libXcursor.so.1 (0x00007f467f6bf000)
        libxkbcommon.so.0 => /lib/x86_64-linux-gnu/libxkbcommon.so.0 (0x00007f467f678000)
        libwayland-cursor.so.0 => /lib/x86_64-linux-gnu/libwayland-cursor.so.0 (0x00007f467f66e000)
        libXext.so.6 => /lib/x86_64-linux-gnu/libXext.so.6 (0x00007f467f659000)
        libmount.so.1 => /lib/x86_64-linux-gnu/libmount.so.1 (0x00007f467f615000)
        libselinux.so.1 => /lib/x86_64-linux-gnu/libselinux.so.1 (0x00007f467f5e9000)
        libatomic.so.1 => /lib/x86_64-linux-gnu/libatomic.so.1 (0x00007f467f5df000)
        libffi.so.8 => /lib/x86_64-linux-gnu/libffi.so.8 (0x00007f467f5d2000)
        libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007f467f55c000)
        libGLdispatch.so.0 => /lib/x86_64-linux-gnu/libGLdispatch.so.0 (0x00007f467f4a4000)
        libicudata.so.70 => /lib/x86_64-linux-gnu/libicudata.so.70 (0x00007f467d800000)
        liblzma.so.5 => /lib/x86_64-linux-gnu/liblzma.so.5 (0x00007f467f479000)
        libzstd.so.1 => /lib/x86_64-linux-gnu/libzstd.so.1 (0x00007f467d731000)
        liblz4.so.1 => /lib/x86_64-linux-gnu/liblz4.so.1 (0x00007f467f459000)
        libcap.so.2 => /lib/x86_64-linux-gnu/libcap.so.2 (0x00007f467f44e000)
        libthai.so.0 => /lib/x86_64-linux-gnu/libthai.so.0 (0x00007f467f443000)
        libgraphite2.so.3 => /lib/x86_64-linux-gnu/libgraphite2.so.3 (0x00007f467d70a000)
        libpixman-1.so.0 => /lib/x86_64-linux-gnu/libpixman-1.so.0 (0x00007f467d65f000)
        libxcb-shm.so.0 => /lib/x86_64-linux-gnu/libxcb-shm.so.0 (0x00007f467f43e000)
        libxcb.so.1 => /lib/x86_64-linux-gnu/libxcb.so.1 (0x00007f467d635000)
        libxcb-render.so.0 => /lib/x86_64-linux-gnu/libxcb-render.so.0 (0x00007f467f42f000)
        libXrender.so.1 => /lib/x86_64-linux-gnu/libXrender.so.1 (0x00007f467f422000)
        libwoff2common.so.1.0.2 => /lib/x86_64-linux-gnu/libwoff2common.so.1.0.2 (0x00007f467d630000)
        libbrotlidec.so.1 => /lib/x86_64-linux-gnu/libbrotlidec.so.1 (0x00007f467d622000)
        libexpat.so.1 => /lib/x86_64-linux-gnu/libexpat.so.1 (0x00007f467d5f1000)
        libuuid.so.1 => /lib/x86_64-linux-gnu/libuuid.so.1 (0x00007f467d5e8000)
        libgpg-error.so.0 => /lib/x86_64-linux-gnu/libgpg-error.so.0 (0x00007f467d5c2000)
        libunwind.so.8 => /lib/x86_64-linux-gnu/libunwind.so.8 (0x00007f467d5a7000)
        libdw.so.1 => /lib/x86_64-linux-gnu/libdw.so.1 (0x00007f467d4fb000)
        liborc-0.4.so.0 => /lib/x86_64-linux-gnu/liborc-0.4.so.0 (0x00007f467d476000)
        libgstallocators-1.0.so.0 => /lib/x86_64-linux-gnu/libgstallocators-1.0.so.0 (0x00007f467d46f000)
        libGL.so.1 => /lib/x86_64-linux-gnu/libGL.so.1 (0x00007f467d3e8000)
        libX11-xcb.so.1 => /lib/x86_64-linux-gnu/libX11-xcb.so.1 (0x00007f467d3e3000)
        libgudev-1.0.so.0 => /lib/x86_64-linux-gnu/libgudev-1.0.so.0 (0x00007f467d3d5000)
        libdrm.so.2 => /lib/x86_64-linux-gnu/libdrm.so.2 (0x00007f467d3bf000)
        libgbm.so.1 => /lib/x86_64-linux-gnu/libgbm.so.1 (0x00007f467d3ae000)
        libpsl.so.5 => /lib/x86_64-linux-gnu/libpsl.so.5 (0x00007f467d39a000)
        libgssapi_krb5.so.2 => /lib/x86_64-linux-gnu/libgssapi_krb5.so.2 (0x00007f467d344000)
        libevdev.so.2 => /lib/x86_64-linux-gnu/libevdev.so.2 (0x00007f467d327000)
        libdbus-1.so.3 => /lib/x86_64-linux-gnu/libdbus-1.so.3 (0x00007f467d2d9000)
        libatspi.so.0 => /lib/x86_64-linux-gnu/libatspi.so.0 (0x00007f467d29f000)
        libblkid.so.1 => /lib/x86_64-linux-gnu/libblkid.so.1 (0x00007f467d266000)
        libpcre2-8.so.0 => /lib/x86_64-linux-gnu/libpcre2-8.so.0 (0x00007f467d1cf000)
        libdatrie.so.1 => /lib/x86_64-linux-gnu/libdatrie.so.1 (0x00007f467d1c6000)
        libXau.so.6 => /lib/x86_64-linux-gnu/libXau.so.6 (0x00007f467d1c0000)
        libXdmcp.so.6 => /lib/x86_64-linux-gnu/libXdmcp.so.6 (0x00007f467d1b8000)
        libbrotlicommon.so.1 => /lib/x86_64-linux-gnu/libbrotlicommon.so.1 (0x00007f467d193000)
        libelf.so.1 => /lib/x86_64-linux-gnu/libelf.so.1 (0x00007f467d175000)
        libbz2.so.1.0 => /lib/x86_64-linux-gnu/libbz2.so.1.0 (0x00007f467d162000)
        libudev.so.1 => /lib/x86_64-linux-gnu/libudev.so.1 (0x00007f467d138000)
        libunistring.so.2 => /lib/x86_64-linux-gnu/libunistring.so.2 (0x00007f467cf8e000)
        libidn2.so.0 => /lib/x86_64-linux-gnu/libidn2.so.0 (0x00007f467cf6b000)
        libkrb5.so.3 => /lib/x86_64-linux-gnu/libkrb5.so.3 (0x00007f467cea0000)
        libk5crypto.so.3 => /lib/x86_64-linux-gnu/libk5crypto.so.3 (0x00007f467ce71000)
        libcom_err.so.2 => /lib/x86_64-linux-gnu/libcom_err.so.2 (0x00007f467ce6b000)
        libkrb5support.so.0 => /lib/x86_64-linux-gnu/libkrb5support.so.0 (0x00007f467ce5d000)
        libbsd.so.0 => /lib/x86_64-linux-gnu/libbsd.so.0 (0x00007f467ce43000)
        libkeyutils.so.1 => /lib/x86_64-linux-gnu/libkeyutils.so.1 (0x00007f467ce3c000)
        libresolv.so.2 => /lib/x86_64-linux-gnu/libresolv.so.2 (0x00007f467ce28000)
        libmd.so.0 => /lib/x86_64-linux-gnu/libmd.so.0 (0x00007f467ce1b000)

I do actually have go-sqlite as a dependency... I forgot it uses cgo. But that's the only one that does, and I've been using it for months before I used Wails, and haven't encountered this problem before when I had nil pointer dereferences.

@leaanthony
Copy link
Member

Awesome that you're able to reproduce! What happens if you run it through gdb? Does it give you more clues (better backtrace 🤞 )?

@mholt
Copy link
Contributor Author

mholt commented Nov 28, 2022

@leaanthony It just says:

Thread 13 "app" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fff9affd640 (LWP 4070999)]
0x0000000001de4af0 in main.main.func1 () at /home/matt/Dev/app/main.go:25
25                      log.Println(t.Unix())

So, it's nice that it reveals the actual source of the signal at this moment! Of course this an induced panic. But if I continue the execution, we still see the problem:

(gdb) continue
Continuing.
[Thread 0x7fff197fc640 (LWP 4071016) exited]
[Thread 0x7fff78ffb640 (LWP 4071008) exited]
[New Thread 0x7fff197fc640 (LWP 4071338)]
signal 11 received but handler not on signal stack
fatal error: non-Go code set up signal handler without SA_ONSTACK flag

runtime stack:
runtime.throw({0x22b14ff?, 0xc000042400?})
        /usr/local/go/src/runtime/panic.go:1047 +0x5d fp=0xc00011a758 sp=0xc00011a728 pc=0x44dbfd
runtime.sigNotOnStack(0xb)
        /usr/local/go/src/runtime/signal_unix.go:1020 +0x65 fp=0xc00011a778 sp=0xc00011a758 pc=0x465305
runtime.adjustSignalStack(0xb, 0xc000800000, 0x0?)
        /usr/local/go/src/runtime/signal_unix.go:581 +0x156 fp=0xc00011a7d8 sp=0xc00011a778 pc=0x464156
runtime.sigtrampgo(0xb, 0xc00011aaf0, 0xc00011a9c0)
        /usr/local/go/src/runtime/signal_unix.go:469 +0x13b fp=0xc00011a850 sp=0xc00011a7d8 pc=0x463e3b
runtime.sigtramp()
        /usr/local/go/src/runtime/sys_linux_amd64.s:359 +0x46 fp=0xc00011a8a0 sp=0xc00011a850 pc=0x484b46

goroutine 17 [syscall, locked to thread]:
runtime.goexit()
        /usr/local/go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc0000a6fe8 sp=0xc0000a6fe0 pc=0x482ea1

goroutine 1 [syscall, locked to thread]:
runtime.cgocall(0x1ebfb70, 0xc000bc7b18)
        /usr/local/go/src/runtime/cgocall.go:158 +0x5c fp=0xc000bc7af0 sp=0xc000bc7ab8 pc=0x41149c
github.com/wailsapp/wails/v2/internal/frontend/desktop/linux._Cfunc_gtk_main()
        _cgo_gotypes.go:1068 +0x45 fp=0xc000bc7b18 sp=0xc000bc7af0 pc=0xd1b105
github.com/wailsapp/wails/v2/internal/frontend/desktop/linux.(*Frontend).RunMainLoop(0xc00076b080)
        /home/matt/go/pkg/mod/github.com/wailsapp/wails/v2@v2.2.0/internal/frontend/desktop/linux/frontend.go:57 +0x1c fp=0xc000bc7b28 sp=0xc000bc7b18 pc=0xd1db3c
github.com/wailsapp/wails/v2/internal/app.(*App).Run(0xc0007aa5f0)
        /home/matt/go/pkg/mod/github.com/wailsapp/wails/v2@v2.2.0/internal/app/app_production.go:19 +0x72 fp=0xc000bc7b90 sp=0xc000bc7b28 pc=0xd353d2
github.com/wailsapp/wails/v2/pkg/application.(*Application).Run(0xc00029b068)
        /home/matt/go/pkg/mod/github.com/wailsapp/wails/v2@v2.2.0/pkg/application/application.go:69 +0x169 fp=0xc000bc7c08 sp=0xc000bc7b90 pc=0xd37129
github.com/wailsapp/wails/v2.Run(0xc0007bd560)
        /home/matt/go/pkg/mod/github.com/wailsapp/wails/v2@v2.2.0/wails.go:14 +0x33 fp=0xc000bc7c48 sp=0xc000bc7c08 pc=0xd372b3
github.com/mholt/app/application.(*App).Run(0xc00071f7d0)
        /home/matt/Dev/app/application/app.go:71 +0x333 fp=0xc000bc7cd0 sp=0xc000bc7c48 pc=0x1d85553
github.com/mholt/app/cmd.Main()
        /home/matt/Dev/app/cmd/cmd.go:61 +0x6ef fp=0xc000bc7f68 sp=0xc000bc7cd0 pc=0x1da3f8f
main.main()
        /home/matt/Dev/app/main.go:27 +0x2a fp=0xc000bc7f80 sp=0xc000bc7f68 pc=0x1de4bea
runtime.main()
        /usr/local/go/src/runtime/proc.go:250 +0x1d8 fp=0xc000bc7fe0 sp=0xc000bc7f80 pc=0x450398
runtime.goexit()
        /usr/local/go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc000bc7fe8 sp=0xc000bc7fe0 pc=0x482ea1
.
.
.
Thread 13 "app" received signal SIGSEGV, Segmentation fault.
0x0000000000474e29 in runtime.gentraceback (pc0=4523965, sp0=824634875392, lr0=<optimized out>, gp=0xc000783380, skip=<optimized out>, pcbuf=0x0, max=100, callback={void (runtime.stkframe *, void *, bool *)} 0xc00011a3a8, v=0x0, flags=0, ~r0=<optimized out>) at /usr/local/go/src/runtime/traceback.go:246
246                                     if doPrint && gp.m.incgo && f.funcID == funcID_sigpanic {

Does that help?

@leaanthony
Copy link
Member

Thanks for the update. I can reproduce with a bog-standard default template. So firstly, I don't think this is a show-stopper as such because a nil dereference has happened anyway so it's going to go boom. What do you think is the expected behaviour here? It would be good if we can get it to call back to Go's handler. I can only assume there's a standard way of dealing with this scenario and my guess at this point is to include a signal handler in C that overrides the existing one created by the library (I think it's gtk2webkit) with the SA_ONSTACK flag. I'll need to do a bit more digging.

@mholt
Copy link
Contributor Author

mholt commented Nov 28, 2022

Yeah, exactly, the root cause is in my code, not Wails. The problem is that something about the Wails builds eats the actual error so I can't fix my code 😭 (unless I run without wails, which requires quite a bit of runaround to work with go build)

Thanks for looking into it. I'm out of my element here in C libraries.

@leaanthony
Copy link
Member

I think we can do something here though. If we install a signal handler we may be able to override the existing C signal handler and just propagate that back through to Go. What seems weird to me is that the C signal handler is eating the Go signal. I would have thought that would only have been dealt with by Go

@mholt
Copy link
Contributor Author

mholt commented Nov 28, 2022

Makes sense. Yeah, I find it surprising too.

@mholt
Copy link
Contributor Author

mholt commented Nov 29, 2022

So I was able to reproduce the original panic in my code while running under gdb. Unfortunately, this time, the only error message I get before doing continue is:

Thread 12 "app" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fffab7fe640 (LWP 172624)]
0x000000000144419c in ?? ()
(gdb) 

So even with gdb I cannot find the underlying panic and fix it :(

@leaanthony
Copy link
Member

Oooph that's frustrating. There must be other examples of people using CGO who experience this...

@mholt
Copy link
Contributor Author

mholt commented Nov 29, 2022

Not really sure what to look for, but a few things I stumbled upon:

That one comment says:

Alternatively, LibreOfficeKit in general or that go-libreofficekit in particular might want to not call osl_addSignalHandler (which is the only code path that leads to that)

Is there a similar function for gtk/webkit that Wails calls, do you know?

@leaanthony
Copy link
Member

leaanthony commented Nov 29, 2022

Not in Wails, but maybe in gtk/webkit. We can try adding a signal handler like they do in the Magick library and see if that helps. If we set it up in the Run() method then that should be late enough to override any previous handlers in C but early enough to catch any user-code errors.

@mholt
Copy link
Contributor Author

mholt commented Nov 29, 2022

@leaanthony Alright, cool. Thanks.

And don't stress on this particular issue; I've spun up my dusty old HTTP server code that I was using before Wails, used it to execute my buggy code path, and found my panic details from a build using go run. So this isn't a blocker for me, at least until the next bug 😅

Thanks for all you do!

@0xsimulacra
Copy link

For anyone having this proble; in the future: check if you have any nil pointer dereference in your code, it might cause this same issue on wails (see: #3965)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants