{"record":{"id":"0832e56251193ad3","repo":"XTLS/Xray-core","slug":"failed-to-open","errorCode":null,"errorMessage":"failed to open ","messagePattern":"failed to open ","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"common/geodata/geodat_loader.go","lineNumber":19,"sourceCode":"package geodata\n\nimport (\n\t\"bufio\"\n\t\"bytes\"\n\t\"io\"\n\t\"runtime\"\n\t\"strings\"\n\n\t\"github.com/xtls/xray-core/common/errors\"\n\t\"github.com/xtls/xray-core/common/platform/filesystem\"\n\n\t\"google.golang.org/protobuf/proto\"\n)\n\nfunc checkFile(file, code string) error {\n\tr, err := filesystem.OpenAsset(file)\n\tif err != nil {\n\t\treturn errors.New(\"failed to open \", file).Base(err)\n\t}\n\tdefer r.Close()\n\tif _, err := find(r, []byte(code), false); err != nil {\n\t\treturn errors.New(\"failed to check code \", code, \" from \", file).Base(err)\n\t}\n\treturn nil\n}\n\nfunc loadFile(file, code string) ([]byte, error) {\n\truntime.GC() // peak mem\n\tr, err := filesystem.OpenAsset(file)\n\tif err != nil {\n\t\treturn nil, errors.New(\"failed to open \", file).Base(err)\n\t}\n\tdefer r.Close()\n\tbs, err := find(r, []byte(code), true)\n\tif err != nil {\n\t\treturn nil, errors.New(\"failed to load code \", code, \" from \", file).Base(err)","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/XTLS/Xray-core/blob/7d214f8b094f75322fa3990f8aadad1c912f24f5/common/geodata/geodat_loader.go#L1-L37","documentation":"Wrapped error (message continues with the file path; underlying error attached via .Base) from checkFile when filesystem.OpenAsset cannot open the geodata file (geoip.dat / geosite.dat). OpenAsset resolves the asset location from XRAY_LOCATION_ASSET / XRAY_LOCATION_ASSET_CONF or platform defaults; failure means the file is missing or unreadable at that resolved path.","triggerScenarios":"checkFile(file, code) — invoked when Xray starts with geoip/geosite rules — and the resolved asset path contains no such file: fresh installs that never downloaded dat files, wrong XRAY_LOCATION_ASSET, or unreadable permissions on the dat file.","commonSituations":"Running xray from a directory without geosite.dat while the config uses geosite:cn-style routing; Docker images or systemd units where the asset env var points elsewhere; dat file owned by root with mode 600 under a different user.","solutions":["Download the official geoip.dat and geosite.dat (e.g. from v2fly domain-list-community / geoip releases) into the resolved asset directory shown in the error path.","Set XRAY_LOCATION_ASSET to the directory that actually contains the dat files and restart.","Check file permissions (readable by the xray process user) and that the filename matches exactly, including case."],"exampleFix":"# before\n$ XRAY_LOCATION_ASSET=/opt/xray/assets xray run -c config.json\n# error: failed to open /opt/xray/assets/geosite.dat\n\n# after\n$ ls /opt/xray/assets # confirm files; if absent:\n$ wget -O /opt/xray/assets/geosite.dat https://github.com/v2fly/domain-list-community/releases/latest/download/dlc.dat\n$ wget -O /opt/xray/assets/geoip.dat https://github.com/v2fly/geoip/releases/latest/download/geoip.dat","handlingStrategy":"validation","validationCode":"f, err := os.Open(filepath.Join(assetDir, \"geosite.dat\"))\nif err != nil { /* download or fix XRAY_LOCATION_ASSET before start */ }\nf.Close()","typeGuard":null,"tryCatchPattern":"err := checkFile(\"geosite.dat\", \"cn\")\nif err != nil { log.Fatal(err) /* surface asset path problem to operator */ }","preventionTips":["Pre-download dat files in Dockerfile/systemd prestart","Pin XRAY_LOCATION_ASSET to a stable directory","Verify read permissions for the service user"],"tags":["geodata","filesystem","environment","routing","xray"],"backgroundTag":null,"analyzedSha":"7d214f8b094f75322fa3990f8aadad1c912f24f5","analyzedAt":"2026-08-15T14:26:24.325Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}