{"record":{"id":"8775dbbc00476ab0","repo":"netbirdio/netbird","slug":"invalid-tunnel-file-descriptor-fd-is-0-swift-fai","errorCode":null,"errorMessage":"invalid tunnel file descriptor: fd is 0 (Swift failed to locate utun socket)","messagePattern":"invalid tunnel file descriptor: fd is 0 \\(Swift failed to locate utun socket\\)","errorType":"exception","errorClass":"ErrInvalidTunnelFD","httpStatus":null,"severity":"error","filePath":"client/iface/device/device_ios.go","lineNumber":48,"sourceCode":"\tudpMux         *udpmux.UniversalUDPMuxDefault\n\tconfigurer     WGConfigurer\n}\n\nfunc NewTunDevice(name string, address wgaddr.Address, port int, key string, mtu uint16, iceBind *bind.ICEBind, tunFd int) *TunDevice {\n\treturn &TunDevice{\n\t\tname:    name,\n\t\taddress: address,\n\t\tport:    port,\n\t\tkey:     key,\n\t\tmtu:     mtu,\n\t\ticeBind: iceBind,\n\t\ttunFd:   tunFd,\n\t}\n}\n\n// ErrInvalidTunnelFD is returned when the tunnel file descriptor is invalid (0).\n// This typically means the Swift code couldn't find the utun control socket.\nvar ErrInvalidTunnelFD = fmt.Errorf(\"invalid tunnel file descriptor: fd is 0 (Swift failed to locate utun socket)\")\n\nfunc (t *TunDevice) Create() (WGConfigurer, error) {\n\tlog.Infof(\"create tun interface\")\n\n\tvar tunDevice tun.Device\n\tvar err error\n\n\t// Validate the tunnel file descriptor.\n\t// On iOS/tvOS, the FD must be provided by the NEPacketTunnelProvider.\n\t// A value of 0 means the Swift code couldn't find the utun control socket\n\t// (the low-level APIs like ctl_info, sockaddr_ctl may not be exposed in\n\t// tvOS SDK headers). This is a hard error - there's no viable fallback\n\t// since tun.CreateTUN() cannot work within the iOS/tvOS sandbox.\n\tif t.tunFd == 0 {\n\t\tlog.Errorf(\"Tunnel file descriptor is 0 - Swift code failed to locate the utun control socket. \" +\n\t\t\t\"On tvOS, ensure the NEPacketTunnelProvider is properly configured and the tunnel is started.\")\n\t\treturn nil, ErrInvalidTunnelFD\n\t}","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/netbirdio/netbird/blob/93e97f4bf1ad715072dcb3fb6cdb1763431b5a9c/client/iface/device/device_ios.go#L30-L66","documentation":"Error \"invalid tunnel file descriptor: fd is 0 (Swift failed to locate utun socket)\" thrown in netbirdio/netbird.","triggerScenarios":"Thrown at client/iface/device/device_ios.go:48 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"93e97f4bf1ad715072dcb3fb6cdb1763431b5a9c","analyzedAt":"2026-08-16T03:09:19.136Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}