[GH-ISSUE #3336] macOS: client from dev hangs at startup in libagw (Go runtime sigaltstack fails with EPERM) #3202

Open
opened 2026-10-30 04:57:45 +07:00 by bsakaguchi · 0 comments
Owner

Originally created by @ehles on GitHub (Oct 27, 2026).
Original GitHub issue: https://github.com/amnezia-vpn/amnezia-client/issues/3336

Describe the bug
A macOS client built from dev (after #3028 "use libagw") hangs right after launch. The window appears, then the app stops responding and uses one core at 100%. Release 5.0.4.2, which does not include libagw, starts normally when built the same way.

The main thread is stuck in the Go runtime of libagw:

main
 → AmneziaApplication::init
 → UpdateController::checkForUpdates
 → GatewayController::GatewayController
 → agw_client_create
 → crosscall2            (first call into Go from the main thread)
 → runtime.sigaltstack_trampoline
 → runtime.notok         (str x8, [x8]; b .)

sigaltstack returns -1 with errno = EPERM, so the runtime calls notok, which writes to address 0. The resulting SIGSEGV is caught and the faulting instruction runs again, so the thread spins forever instead of crashing.

On this first cgo callback the runtime finds the main thread's alternate signal stack disabled and tries to install its own (minitSignalStack → signalstack). The kernel refuses because the thread's signal stack flags already have SS_ONSTACK set:

Point (main thread) sigaltstack(NULL, &ss).ss_flags
main, start of AmneziaApplication::init SS_DISABLE (4)
after QQmlApplicationEngine::load SS_ONSTACK | SS_DISABLE (5)
UpdateController::checkForUpdates, crosscall2 SS_ONSTACK | SS_DISABLE (5)

No sigaltstack, sigaction or _sigtramp runs on the main thread during QQmlApplicationEngine::load, so I could not find what sets the flag. sigaltstack calls made by Go on its own threads (32 KiB stacks) succeed.

To Reproduce

  1. Build dev for macOS: deploy/build.sh --generator Ninja --installer all (Qt 6.10.1, libagw 1.0.8 built with Go 1.27.1 from the Conan remote).
  2. Launch AmneziaVPN.app.
  3. The UI loads, then the app hangs. Under lldb the main thread stops with EXC_BAD_ACCESS (address=0x0) in runtime.notok.

Expected behavior
The app starts, and GatewayController creates the libagw client without hanging the main thread.

Log files
Nothing relevant is logged before the hang: the last lines are the normal startup messages.

Desktop:

  • OS: macOS 26.3.1, Apple Silicon (arm64)
  • Version: dev at 3121775a (5.1.0.3), local build

Additional context

  • Ideas for a workaround, not tested: create the libagw client off the main thread, or install an alternate signal stack on the main thread early in main() so the Go runtime adopts it instead of trying to set its own.
  • Possibly related on the Go side: golang/go#80622 (darwin/arm64 cgo callbacks from host threads).
Originally created by @ehles on GitHub (Oct 27, 2026). Original GitHub issue: https://github.com/amnezia-vpn/amnezia-client/issues/3336 **Describe the bug** A macOS client built from `dev` (after #3028 "use libagw") hangs right after launch. The window appears, then the app stops responding and uses one core at 100%. Release 5.0.4.2, which does not include libagw, starts normally when built the same way. The main thread is stuck in the Go runtime of libagw: ``` main → AmneziaApplication::init → UpdateController::checkForUpdates → GatewayController::GatewayController → agw_client_create → crosscall2 (first call into Go from the main thread) → runtime.sigaltstack_trampoline → runtime.notok (str x8, [x8]; b .) ``` `sigaltstack` returns -1 with `errno = EPERM`, so the runtime calls `notok`, which writes to address 0. The resulting SIGSEGV is caught and the faulting instruction runs again, so the thread spins forever instead of crashing. On this first cgo callback the runtime finds the main thread's alternate signal stack disabled and tries to install its own (`minitSignalStack` → `signalstack`). The kernel refuses because the thread's signal stack flags already have `SS_ONSTACK` set: | Point (main thread) | `sigaltstack(NULL, &ss).ss_flags` | |---|---| | `main`, start of `AmneziaApplication::init` | `SS_DISABLE` (4) | | after `QQmlApplicationEngine::load` | `SS_ONSTACK \| SS_DISABLE` (5) | | `UpdateController::checkForUpdates`, `crosscall2` | `SS_ONSTACK \| SS_DISABLE` (5) | No `sigaltstack`, `sigaction` or `_sigtramp` runs on the main thread during `QQmlApplicationEngine::load`, so I could not find what sets the flag. `sigaltstack` calls made by Go on its own threads (32 KiB stacks) succeed. **To Reproduce** 1. Build `dev` for macOS: `deploy/build.sh --generator Ninja --installer all` (Qt 6.10.1, libagw 1.0.8 built with Go 1.27.1 from the Conan remote). 2. Launch `AmneziaVPN.app`. 3. The UI loads, then the app hangs. Under lldb the main thread stops with `EXC_BAD_ACCESS (address=0x0)` in `runtime.notok`. **Expected behavior** The app starts, and `GatewayController` creates the libagw client without hanging the main thread. **Log files** Nothing relevant is logged before the hang: the last lines are the normal startup messages. **Desktop:** - OS: macOS 26.3.1, Apple Silicon (arm64) - Version: `dev` at 3121775a (5.1.0.3), local build **Additional context** - Ideas for a workaround, not tested: create the libagw client off the main thread, or install an alternate signal stack on the main thread early in `main()` so the Go runtime adopts it instead of trying to set its own. - Possibly related on the Go side: golang/go#80622 (darwin/arm64 cgo callbacks from host threads).
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
amnezia-vpn/amnezia-client#3202
No description provided.