XTLS/Xray-core · warning

failed to delete system route

Error message

failed to delete system route

What it means

During teardown (unsetSystemRoutes), Xray deletes the system routes it installed. A failing netlink.RouteDel is collected into a combined error. Almost always benign: the route was already removed externally or vanished with the TUN link's destruction.

Source

Thrown at proxy/tun/tun_linux.go:297

			LinkIndex: tunIndex,
			Dst:       ipNet,
			Priority:  1,
		}
		if err := netlink.RouteAdd(&route); err != nil {
			_ = t.unsetSystemRoutes()
			return errors.New("failed to add system route ", cidr).Base(err)
		}
		t.systemRoutes = append(t.systemRoutes, route)
	}
	return nil
}

func (t *LinuxTun) unsetSystemRoutes() error {
	var errs []error
	for i := len(t.systemRoutes) - 1; i >= 0; i-- {
		route := t.systemRoutes[i]
		if err := netlink.RouteDel(&route); err != nil {
			errs = append(errs, errors.New("failed to delete system route").Base(err))
		}
	}
	t.systemRoutes = nil
	return errors.Combine(errs...)
}

func (t *LinuxTun) monitorRouteChanges() {
	routeCh := make(chan netlink.RouteUpdate)
	if err := netlink.RouteSubscribe(routeCh, t.routeMonitorStop); err != nil {
		errors.LogInfoInner(context.Background(), err, "[tun] failed to subscribe route changes")
		return
	}

	linkCh := make(chan netlink.LinkUpdate)
	if err := netlink.LinkSubscribe(linkCh, t.routeMonitorStop); err != nil {
		errors.LogInfoInner(context.Background(), err, "[tun] failed to subscribe link changes")
		return
	}

View on GitHub (pinned to 7d214f8b09)

Solutions

  1. Verify with `ip route` that the routes are gone; if absent, ignore the message
  2. Let Xray own route lifecycle exclusively for the TUN device
  3. Prefer graceful stop signals over kill -9 so cleanup sees a consistent state
Defensive patterns

Strategy: try-catch

Try / catch

if err := tun.Close(); err != nil {
	log.Warnf("route cleanup: %v (verify with `ip route`)", err)
}

Prevention

When it happens

Trigger: Route manually deleted or replaced while Xray ran; TUN interface destroyed before Xray's cleanup; kernel auto-removed routes when the link went down.

Common situations: SIGKILL followed by manual cleanup, then clean stop of Xray; system shutdown ordering; another network daemon managing the same prefixes.

Related errors


AI-assisted analysis of XTLS/Xray-core@7d214f8b09 (2026-08-15). Data as JSON: /api/errors/3c8500cc0830523a. Report an issue: GitHub.