mirror of
https://github.com/netbirdio/ios-client.git
synced 2026-09-23 09:28:33 -07:00
The packet tunnel extension crash-loops (EXC_BAD_ACCESS, KERN_INVALID_ADDRESS at 0x28) on wifi<->cellular path flapping: it connects briefly, then the extension is killed and relaunched every ~6-12s, so no IP/device name renders and iOS never activates the VPN (T-808). Root cause (code-derived; not yet confirmed against a symbolicated build-7 crash because no dSYM was available): the Go engine retains NetworkChangeListener and DNSManager for the lifetime of the SDK client they were created with. When the adapter is swapped/torn down (profile switch, or a restart triggered by flapping) the old client can still fire a late onNetworkChanged/applyDns into the now-stale listener, which dereferences a tunnel manager whose owning provider has already been deallocated -> use-after-free. Fix: make the Go-held listeners null-safe and explicitly detachable. - NetworkChangeListener / DNSManager: tunnelManager is now optional; every Go callback runs on a serial queue behind a guard (isValid + non-nil tunnelManager). Late/in-flight callbacks become no-ops instead of crashing. Added invalidate() to detach, serialized on the same queue. - NetBirdAdapter: added invalidateListeners(). Deliberately NOT called from stop()/restart (the same adapter is reused there and must keep delivering callbacks) -- only when the adapter is actually discarded. - PacketTunnelProvider: invalidate the outgoing adapter's listeners before replacing it at the two reconfigure sites (startTunnel, handleAppMessage). Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>