XTLS/Xray-core · error
invalid xray.tun.fd: file descriptor must be >= 3
Error message
invalid xray.tun.fd: file descriptor must be >= 3
What it means
openFromEnv parsed XRAY_TUN_FD successfully but the value is less than 3. Descriptors 0, 1, and 2 are stdin/stdout/stderr, so they cannot be a TUN device; values below 3 indicate a misconfigured or garbage environment variable.
Solutions
- Pass a real file descriptor (>= 3) obtained from opening/creating the TUN device in the parent process
- Confirm the parent opened the TUN fd and passed it via fork/exec inheritance or a socket
- Remove XRAY_TUN_FD if the fd-passing setup is not in use
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at proxy/tun/tun_linux.go:84 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/30482c5584f2994b.
Report an issue: GitHub.
Appendix: source
Thrown at proxy/tun/tun_linux.go:84
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 {
return -1, nil, true, errors.New("invalid ", platform.TunFdKey, ": TUN device must use IFF_NO_PI")
}
View on GitHub (pinned to 7d214f8b09)