XTLS/Xray-core · error
invalid xray.tun.fd
Error message
invalid xray.tun.fd
What it means
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.
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
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at proxy/tun/tun_linux.go:81 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of XTLS/Xray-core@7d214f8b09 (2026-08-15).
Data as JSON: /api/errors/b8ee8e56e6d40ccc.
Report an issue: GitHub.
Appendix: source
Thrown at proxy/tun/tun_linux.go:81
linuxTun := &LinuxTun{
tunFd: tunFd,
tunLink: tunLink,
options: options,
ownsTun: true,
}
return linuxTun, nil
}
func openFromEnv(expectedName string) (int, netlink.Link, bool, error) {
fdStr := platform.NewEnvFlag(platform.TunFdKey).GetValue(func() string { return "" })
if fdStr == "" {
return -1, nil, false, nil
}
fd, err := strconv.Atoi(fdStr)
if err != nil {
return -1, nil, true, errors.New("invalid ", platform.TunFdKey).Base(err)
}
if fd < 3 {
return -1, nil, true, errors.New("invalid ", platform.TunFdKey, ": file descriptor must be >= 3")
}
ifr, err := unix.NewIfreq("")
if err != nil {
return -1, nil, true, err
}
if err = unix.IoctlIfreq(fd, unix.TUNGETIFF, ifr); err != nil {
return -1, nil, true, err
}
flags := ifr.Uint16()
if flags&unix.IFF_TUN == 0 {
return -1, nil, true, errors.New("invalid ", platform.TunFdKey, ": file descriptor is not a TUN device")
}
if flags&unix.IFF_NO_PI == 0 {View on GitHub (pinned to 7d214f8b09)