vaxilu/x-ui · error
xray is not running
Error message
xray is not running
What it means
GetXrayTraffic in web/service/xray.go checks IsXrayRunning() before querying traffic stats and returns this error if the xray core process is not currently running. Since traffic is collected via the xray stats API (p.GetTraffic), there is no process to query, so the service fails fast rather than returning empty data.
Source
Thrown at web/service/xray.go:83
}
inbounds, err := s.inboundService.GetAllInbounds()
if err != nil {
return nil, err
}
for _, inbound := range inbounds {
if !inbound.Enable {
continue
}
inboundConfig := inbound.GenXrayInboundConfig()
xrayConfig.InboundConfigs = append(xrayConfig.InboundConfigs, *inboundConfig)
}
return xrayConfig, nil
}
func (s *XrayService) GetXrayTraffic() ([]*xray.Traffic, error) {
if !s.IsXrayRunning() {
return nil, errors.New("xray is not running")
}
return p.GetTraffic(true)
}
func (s *XrayService) RestartXray(isForce bool) error {
lock.Lock()
defer lock.Unlock()
logger.Debug("restart xray, force:", isForce)
xrayConfig, err := s.GetXrayConfig()
if err != nil {
return err
}
if p != nil && p.IsRunning() {
if !isForce && p.GetConfig().Equals(xrayConfig) {
logger.Debug("not need to restart xray")
return nilView on GitHub (pinned to 9c1be8c57a)
Solutions
- Check the xray log for the underlying startup failure and fix the config
- Click restart xray (RestartXray) after fixing the config
- Verify the xray binary path in panel settings points to an executable file
- Ensure required ports are free and not blocked by another process
Example fix
// before
type := traffic, err := s.GetXrayTraffic()
// after (guard in caller)
traffics, err := s.GetXrayTraffic()
if err != nil {
if err.Error() == "xray is not running" {
logger.Warning("xray not running, skip traffic collection")
return
}
logger.Error("get xray traffic:", err)
} Defensive patterns
Strategy: try-catch
Validate before calling
if !xrayService.IsXrayRunning() {
// skip traffic collection or restart xray first
return nil
} Try / catch
traffics, err := xrayService.GetXrayTraffic()
if err != nil {
if err.Error() == "xray is not running" {
logger.Warning("xray not running; skipping traffic poll")
return
}
logger.Error("traffic poll failed:", err)
} Prevention
- Check IsXrayRunning() before polling traffic
- Monitor xray process health and auto-restart on exit
- Validate xray config after edits and test a restart
- Alert on xray startup failures so the process never silently dies
When it happens
Trigger: The background Run loop calls GetXrayTraffic while xray has crashed, failed to start, or was stopped — e.g. invalid xray config preventing startup, binary missing, or the process exited with a non-zero status.
Common situations: xray failed to start after a config edit; the core binary was deleted during an update; the port xray needs is already in use so startup failed; user stopped xray from the panel while the traffic collector keeps running.
Related errors
AI-assisted analysis of vaxilu/x-ui@9c1be8c57a (2026-09-02).
Data as JSON: /api/errors/e6f9c2fe572610e7.
Report an issue: GitHub.