{"record":{"id":"b8ee8e56e6d40ccc","repo":"XTLS/Xray-core","slug":"invalid-xray-tun-fd","errorCode":null,"errorMessage":"invalid xray.tun.fd","messagePattern":"invalid xray\\.tun\\.fd","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"proxy/tun/tun_linux.go","lineNumber":81,"sourceCode":"\tlinuxTun := &LinuxTun{\n\t\ttunFd:   tunFd,\n\t\ttunLink: tunLink,\n\t\toptions: options,\n\t\townsTun: true,\n\t}\n\n\treturn linuxTun, nil\n}\n\nfunc openFromEnv(expectedName string) (int, netlink.Link, bool, error) {\n\tfdStr := platform.NewEnvFlag(platform.TunFdKey).GetValue(func() string { return \"\" })\n\tif fdStr == \"\" {\n\t\treturn -1, nil, false, nil\n\t}\n\n\tfd, err := strconv.Atoi(fdStr)\n\tif err != nil {\n\t\treturn -1, nil, true, errors.New(\"invalid \", platform.TunFdKey).Base(err)\n\t}\n\tif fd < 3 {\n\t\treturn -1, nil, true, errors.New(\"invalid \", platform.TunFdKey, \": file descriptor must be >= 3\")\n\t}\n\n\tifr, err := unix.NewIfreq(\"\")\n\tif err != nil {\n\t\treturn -1, nil, true, err\n\t}\n\tif err = unix.IoctlIfreq(fd, unix.TUNGETIFF, ifr); err != nil {\n\t\treturn -1, nil, true, err\n\t}\n\n\tflags := ifr.Uint16()\n\tif flags&unix.IFF_TUN == 0 {\n\t\treturn -1, nil, true, errors.New(\"invalid \", platform.TunFdKey, \": file descriptor is not a TUN device\")\n\t}\n\tif flags&unix.IFF_NO_PI == 0 {","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/XTLS/Xray-core/blob/7d214f8b094f75322fa3990f8aadad1c912f24f5/proxy/tun/tun_linux.go#L63-L99","documentation":"openFromEnv read the XRAY_TUN_FD environment variable (non-empty) but strconv.Atoi failed to parse it as an integer. The value is expected to be a pre-opened TUN file descriptor number passed by a parent process (e.g. Android VpnService); any non-numeric value triggers this error.","triggerScenarios":"Thrown at proxy/tun/tun_linux.go:81 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Set XRAY_TUN_FD to a decimal integer string only (e.g. '17'), no 0x prefix, whitespace, or unit suffix","Verify the parent process actually exports the raw fd number","Unset the variable if you did not intend to use a pre-opened TUN fd, letting xray open the TUN itself"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"7d214f8b094f75322fa3990f8aadad1c912f24f5","analyzedAt":"2026-08-15T14:26:24.325Z","contentChangedAt":"2026-08-15T14:26:24.325Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}