TL;DR: Solved
I have linked and not used dependency of https://github.com/dima-u/SwiftyXrayKit and trying to use LibXray directly. It caused crash of go initialization for cgo and go mobile builds before reaching NEPacketTunnelProvider
Just keeping one of the LibXray dependency is quite enough to fix the problem
I spent 9 hours debugging and the text below is what I wanted to originally ask. Maybe a good reminder in README to keep only 1 linked LibXray dependency. At least this issue indexing may save someone's day.
Description
libXray crashes on iOS when used inside a NetworkExtension (PacketTunnelProvider).
The crash happens immediately on startup, before any tunnel logic (startTunnel execution) or traffic handling begins.
This issue is reproducible on latest upstream libXray and Xray-core, without any local patches.
Environment
- iOS: 18.5 (22F76)
- Device: iPhone (arm64)
- IIntegration: NetworkExtension (PacketTunnelProvider)
- Build:
python3 build/main.py apple go (also reproduced with gomobile) on macOS 15.6.1 (24G90) (MacBook M4 Pro)
- Xray-core: v26.3.27 (cloned by build script)
- libXray: latest GitHub main (no local modifications)
- Swift: 6
- Go: 1.26.1
Logs
Crash signature:
EXC_BAD_ACCESS (SIGSEGV)
KERN_INVALID_ADDRESS at 0x0000000000000030
Faulting thread:
thread 2:
_cgo_topofstack
Other threads show Go runtime initialization:
runtime.doInit1
waiter.init.0
In another run, stack also included:
x_cgo_init
init_working_dir
CFBundleGetValueForInfoDictionaryKey
_os_log_debug_impl
Reproduce
Basic NEPacketTunnelProvider implementation with + bridge header (if necessary, same happens with go mobile only)
Expected Behavior
libXray should initialize successfully inside a PacketTunnelProvider (os logs, etc) and allow startTunnel call
TL;DR: Solved
I have linked and not used dependency of https://github.com/dima-u/SwiftyXrayKit and trying to use LibXray directly. It caused crash of go initialization for cgo and go mobile builds before reaching
NEPacketTunnelProviderJust keeping one of the LibXray dependency is quite enough to fix the problem
I spent 9 hours debugging and the text below is what I wanted to originally ask. Maybe a good reminder in README to keep only 1 linked LibXray dependency. At least this issue indexing may save someone's day.
Description
libXray crashes on iOS when used inside a NetworkExtension (PacketTunnelProvider).
The crash happens immediately on startup, before any tunnel logic (startTunnel execution) or traffic handling begins.
This issue is reproducible on latest upstream libXray and Xray-core, without any local patches.
Environment
python3 build/main.py apple go(also reproduced with gomobile) on macOS 15.6.1 (24G90) (MacBook M4 Pro)Logs
Crash signature:
Faulting thread:
Other threads show Go runtime initialization:
In another run, stack also included:
Reproduce
Basic
NEPacketTunnelProviderimplementation with + bridge header (if necessary, same happens with go mobile only)Expected Behavior
libXray should initialize successfully inside a PacketTunnelProvider (os logs, etc) and allow
startTunnelcall