Skip to content

[README improve] Crash on iOS NetworkExtension during early libXray initialization #116

@deknowny

Description

@deknowny

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions