{"record":{"id":"8a046bfbaff84b17","repo":"XTLS/Xray-core","slug":"invalid-fakedns-config","errorCode":null,"errorMessage":"invalid fakedns config","messagePattern":"invalid fakedns config","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"infra/conf/fakedns.go","lineNumber":45,"sourceCode":"\t\t\treturn json.Marshal(f.pool)\n\t\t} else if f.pools != nil {\n\t\t\treturn json.Marshal(f.pools)\n\t\t}\n\t}\n\treturn nil, errors.New(\"unexpected config state\")\n}\n\n// UnmarshalJSON implements encoding/json.Unmarshaler.UnmarshalJSON\nfunc (f *FakeDNSConfig) UnmarshalJSON(data []byte) error {\n\tvar pool FakeDNSPoolElementConfig\n\tvar pools []*FakeDNSPoolElementConfig\n\tswitch {\n\tcase json.Unmarshal(data, &pool) == nil:\n\t\tf.pool = &pool\n\tcase json.Unmarshal(data, &pools) == nil:\n\t\tf.pools = pools\n\tdefault:\n\t\treturn errors.New(\"invalid fakedns config\")\n\t}\n\treturn nil\n}\n\nfunc (f *FakeDNSConfig) Build() (*fakedns.FakeDnsPoolMulti, error) {\n\tfakeDNSPool := fakedns.FakeDnsPoolMulti{}\n\n\tif f.pool != nil {\n\t\tfakeDNSPool.Pools = append(fakeDNSPool.Pools, &fakedns.FakeDnsPool{\n\t\t\tIpPool:  f.pool.IPPool,\n\t\t\tLruSize: f.pool.LRUSize,\n\t\t})\n\t\treturn &fakeDNSPool, nil\n\t}\n\n\tif f.pools != nil {\n\t\tfor _, v := range f.pools {\n\t\t\tfakeDNSPool.Pools = append(fakeDNSPool.Pools, &fakedns.FakeDnsPool{IpPool: v.IPPool, LruSize: v.LRUSize})","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/XTLS/Xray-core/blob/7d214f8b094f75322fa3990f8aadad1c912f24f5/infra/conf/fakedns.go#L27-L63","documentation":"Thrown by FakeDNSConfig.UnmarshalJSON when the fakedns JSON value matches neither a single pool object nor an array of pool objects. Xray accepts fakedns either as one {ipPool, lruSize} object or as a list of such objects; anything else (a string, number, or object with wrong shape that fails both unmarshal attempts) yields this error at JSON parse time, not Build time.","triggerScenarios":"\"fakedns\": \"1.2.3.4/24\" (old pre-pool syntax), \"fakedns\": {\"ipPool\": 123} (wrong field types), or \"fakedns\": 42. json.Unmarshal into FakeDNSPoolElementConfig and into []*FakeDNSPoolElementConfig both fail, hitting the default branch.","commonSituations":"Upgrading from very old Xray/V2Ray configs where fakedns took a bare CIDR string; typos in field names (e.g. \"ippool\" vs \"ipPool\") making the strict unmarshal fail when types mismatch; nesting pools one level too deep.","solutions":["Use the object form: {\"ipPool\": \"198.18.0.0/15\", \"lruSize\": 65535} or the array form [{...}, {...}].","Replace old bare-CIDR fakedns strings with the pool object.","Ensure field types are string/int respectively; unknown keys are ignored but wrong types are not.","Run `xray run -test -c config.json` to catch it before starting the service."],"exampleFix":"// before\n\"fakedns\": \"198.18.0.0/15\"\n\n// after\n\"fakedns\": {\"ipPool\": \"198.18.0.0/15\", \"lruSize\": 65535}","handlingStrategy":"validation","validationCode":"function isFakeDNSPool(o) {\n    return o && typeof o === 'object' &&\n        (typeof o.ipPool === 'string' || typeof o.lruSize === 'number');\n}\nfunction isFakeDNSConfig(v) {\n    return isFakeDNSPool(v) || (Array.isArray(v) && v.every(isFakeDNSPool));\n}\nif (!isFakeDNSConfig(cfg.dns?.fakedns)) throw new Error('fakedns must be a pool object or array of pools');","typeGuard":"function isFakeDNSPool(o: unknown): o is { ipPool?: string; lruSize?: number } {\n  return typeof o === 'object' && o !== null &&\n    (o as any).ipPool === undefined || typeof (o as any).ipPool === 'string';\n}","tryCatchPattern":null,"preventionTips":["Use the documented pool object shape ({ipPool, lruSize}) or arrays thereof.","Replace legacy bare-CIDR fakedns strings when upgrading Xray.","Validate config JSON against a JSON schema before loading."],"tags":["go","xray","fakedns","config","json","validation"],"backgroundTag":null,"analyzedSha":"7d214f8b094f75322fa3990f8aadad1c912f24f5","analyzedAt":"2026-08-15T14:26:24.325Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}