{"record":{"id":"e6f9c2fe572610e7","repo":"vaxilu/x-ui","slug":"xray-is-not-running","errorCode":null,"errorMessage":"xray is not running","messagePattern":"xray is not running","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"web/service/xray.go","lineNumber":83,"sourceCode":"\t}\n\n\tinbounds, err := s.inboundService.GetAllInbounds()\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tfor _, inbound := range inbounds {\n\t\tif !inbound.Enable {\n\t\t\tcontinue\n\t\t}\n\t\tinboundConfig := inbound.GenXrayInboundConfig()\n\t\txrayConfig.InboundConfigs = append(xrayConfig.InboundConfigs, *inboundConfig)\n\t}\n\treturn xrayConfig, nil\n}\n\nfunc (s *XrayService) GetXrayTraffic() ([]*xray.Traffic, error) {\n\tif !s.IsXrayRunning() {\n\t\treturn nil, errors.New(\"xray is not running\")\n\t}\n\treturn p.GetTraffic(true)\n}\n\nfunc (s *XrayService) RestartXray(isForce bool) error {\n\tlock.Lock()\n\tdefer lock.Unlock()\n\tlogger.Debug(\"restart xray, force:\", isForce)\n\n\txrayConfig, err := s.GetXrayConfig()\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tif p != nil && p.IsRunning() {\n\t\tif !isForce && p.GetConfig().Equals(xrayConfig) {\n\t\t\tlogger.Debug(\"not need to restart xray\")\n\t\t\treturn nil","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/vaxilu/x-ui/blob/9c1be8c57a53953b47ee7c09a93554e73816f907/web/service/xray.go#L65-L101","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\ntype := traffic, err := s.GetXrayTraffic()\n// after (guard in caller)\n traffics, err := s.GetXrayTraffic()\nif err != nil {\n    if err.Error() == \"xray is not running\" {\n        logger.Warning(\"xray not running, skip traffic collection\")\n        return\n    }\n    logger.Error(\"get xray traffic:\", err)\n}","handlingStrategy":"try-catch","validationCode":"if !xrayService.IsXrayRunning() {\n    // skip traffic collection or restart xray first\n    return nil\n}","typeGuard":null,"tryCatchPattern":"traffics, err := xrayService.GetXrayTraffic()\nif err != nil {\n    if err.Error() == \"xray is not running\" {\n        logger.Warning(\"xray not running; skipping traffic poll\")\n        return\n    }\n    logger.Error(\"traffic poll failed:\", err)\n}","preventionTips":["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"],"tags":["xray","process-lifecycle","traffic"],"backgroundTag":"process-not-running","analyzedSha":"9c1be8c57a53953b47ee7c09a93554e73816f907","analyzedAt":"2026-09-02T18:46:17.308Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}