[GH-ISSUE #107] libwg-go is built with stock Go, so the boottime runtime patch never makes it in (10–15 s stalls after wake) #104

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

Originally created by @Timsonrobl on GitHub (Oct 27, 2026).
Original GitHub issue: https://github.com/amnezia-vpn/amneziawg-android/issues/107

After an Android device wakes from sleep, traffic through AmneziaWG can stall for 10–15 s before connections recover, and longer for apps that add their own reconnect backoff. It isn't tied to a particular phone or app: it shows up on different devices and with different apps, while Windows and macOS clients on the same servers don't have the problem. I reproduced it on AmneziaVPN 5.0.3.0 (Galaxy S25 Ultra, Android 17).

The cause is in the build, not on the device: libwg-go is built with an unpatched Go runtime, so every Android build from this repo since July 2025 is likely affected.

The Makefile downloads Go 1.24.2 and applies goruntime-boottime-over-monotonic.diff to it, but go.mod says go 1.25.0. It has been ahead of the Makefile since f207d7bf (July 2025), when it went to 1.24.4. With the default GOTOOLCHAIN=auto, go build decides the local toolchain is too old, quietly downloads a stock go1.25.0 and builds with that. The patch is applied to a toolchain that never gets used.

You can see it in the shipped library. In the 5.0.3.0 release APK, lib/arm64-v8a/libwg-go.so, runtime.nanotime1 loads clock id 1 before calling clock_gettime:

0x120694: 320003e0   orr  w0, wzr, #1    // CLOCK_MONOTONIC
...
0x1206dc: d2800e28   mov  x8, #113       // clock_gettime
          d4000001   svc  #0

With the patch it would be #7 (CLOCK_BOOTTIME).

In practice: CLOCK_MONOTONIC stops while the phone is suspended, so WireGuard's timers and keypair age stop with it. After a few minutes asleep, the client still thinks its keypair is fresh, while the server has already expired it (REJECT_AFTER_TIME). The client keeps sending into the void until the 15 s "stopped hearing back" timer fires and it handshakes again.

I caught one of these with tcpdump on the server (eth0 and the awg interface) and logcat on the phone. According to dumpsys alarm, the phone had spent 543 of the previous 936 s suspended. The last handshake was 214 s before wake. Once the screen came on, about 45 packets from the phone reached the server's eth0 over 15 s, and none of them showed up decrypted on the awg interface. Then the client logged "Retrying handshake because we stopped hearing back after 15 seconds", and traffic was flowing again 0.4 s later. The app on top added roughly 13 s of its own reconnect backoff, so it was about half a minute from unlock to usable.

On the same phone, with a build that uses Go 1.25.0 + the diff + GOTOOLCHAIN=local:

  • persistent keepalives during sleep come every 25–26 s instead of 71–72 s
  • the client rekeys about every 128 s while the screen is off
  • reconnecting after wake takes under a second

I also ran this repo's build.yml (debug_apk) on my fork: master produces a libwg-go.so that uses clock 1, and the fix branch one that uses clock 7.

Originally created by @Timsonrobl on GitHub (Oct 27, 2026). Original GitHub issue: https://github.com/amnezia-vpn/amneziawg-android/issues/107 After an Android device wakes from sleep, traffic through AmneziaWG can stall for 10–15 s before connections recover, and longer for apps that add their own reconnect backoff. It isn't tied to a particular phone or app: it shows up on different devices and with different apps, while Windows and macOS clients on the same servers don't have the problem. I reproduced it on AmneziaVPN 5.0.3.0 (Galaxy S25 Ultra, Android 17). The cause is in the build, not on the device: libwg-go is built with an unpatched Go runtime, so every Android build from this repo since July 2025 is likely affected. The Makefile downloads Go 1.24.2 and applies `goruntime-boottime-over-monotonic.diff` to it, but go.mod says `go 1.25.0`. It has been ahead of the Makefile since f207d7bf (July 2025), when it went to 1.24.4. With the default `GOTOOLCHAIN=auto`, `go build` decides the local toolchain is too old, quietly downloads a stock go1.25.0 and builds with that. The patch is applied to a toolchain that never gets used. You can see it in the shipped library. In the 5.0.3.0 release APK, `lib/arm64-v8a/libwg-go.so`, `runtime.nanotime1` loads clock id 1 before calling `clock_gettime`: ``` 0x120694: 320003e0 orr w0, wzr, #1 // CLOCK_MONOTONIC ... 0x1206dc: d2800e28 mov x8, #113 // clock_gettime d4000001 svc #0 ``` With the patch it would be `#7` (CLOCK_BOOTTIME). In practice: CLOCK_MONOTONIC stops while the phone is suspended, so WireGuard's timers and keypair age stop with it. After a few minutes asleep, the client still thinks its keypair is fresh, while the server has already expired it (REJECT_AFTER_TIME). The client keeps sending into the void until the 15 s "stopped hearing back" timer fires and it handshakes again. I caught one of these with tcpdump on the server (eth0 and the awg interface) and logcat on the phone. According to `dumpsys alarm`, the phone had spent 543 of the previous 936 s suspended. The last handshake was 214 s before wake. Once the screen came on, about 45 packets from the phone reached the server's eth0 over 15 s, and none of them showed up decrypted on the awg interface. Then the client logged "Retrying handshake because we stopped hearing back after 15 seconds", and traffic was flowing again 0.4 s later. The app on top added roughly 13 s of its own reconnect backoff, so it was about half a minute from unlock to usable. On the same phone, with a build that uses Go 1.25.0 + the diff + `GOTOOLCHAIN=local`: - persistent keepalives during sleep come every 25–26 s instead of 71–72 s - the client rekeys about every 128 s while the screen is off - reconnecting after wake takes under a second I also ran this repo's build.yml (`debug_apk`) on my fork: master produces a libwg-go.so that uses clock 1, and the fix branch one that uses clock 7.
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/amneziawg-android#104
No description provided.