lionsoul2014/ip2region · error · Exception
xdb file IP version mismatch: expected ${ipVersion.name}, go
Error message
xdb file IP version mismatch: expected ${ipVersion.name}, got ${detectedVersion.name} What it means
During Config initialization the xdb file's header is parsed and its detected IP version is compared with the ipVersion the caller requested. If they differ, the exception names both versions, because a searcher built for one address family cannot correctly query a database of the other.
Source
Thrown at binding/cangjie/src/service/config.cj:37
public let searchers: Int64
public init(cachePolicy: Int64, ipVersion: Version, xdbPath: String, searchers: Int64) {
if (searchers <= 0) {
throw Exception("searchers must be > 0")
}
this.cachePolicy = cachePolicy
this.ipVersion = ipVersion
this.xdbPath = xdbPath
this.searchers = searchers
let content = File.readFrom(Path(xdbPath))
this.header = newHeaderFromBytes(content)
// Verify IP version matches
let detectedVersion = versionFromHeader(this.header)
if (detectedVersion.id != ipVersion.id) {
throw Exception("xdb file IP version mismatch: expected ${ipVersion.name}, got ${detectedVersion.name}")
}
if (cachePolicy == VectorIndex) {
this.vIndex = loadVectorIndex(content)
this.cBuffer = Array<Byte>(0, repeat: 0)
} else if (cachePolicy == ContentBuff) {
this.vIndex = Array<Byte>(0, repeat: 0)
this.cBuffer = content
} else {
this.vIndex = Array<Byte>(0, repeat: 0)
this.cBuffer = Array<Byte>(0, repeat: 0)
}
}
public init(cachePolicy: Int64, ipVersion: Version, xdbPath: String) {
this(cachePolicy, ipVersion, xdbPath, 20)
}
}View on GitHub (pinned to c1a1fc7d59)
Solutions
- Make ipVersion match the actual file (check the message's 'got' side to see what the file is)
- Download/load the correct .xdb variant for the configured version (v4 file for V4, v6 file for V6)
- Detect the version from the header first (versionFromHeader) and pass that into Config instead of hardcoding
- Separate config keys for v4 and v6 database paths if both are needed
Example fix
// before let cfg = Config(policy, Version.V6, "ip.v4.xdb", 4) // mismatch // after let header = newHeaderFromBytes(File.readFrom(Path(xdbPath))) let ver = versionFromHeader(header) let cfg = Config(policy, ver, xdbPath, 4)
Defensive patterns
Strategy: validation
Validate before calling
// Cangjie: detect version from file before constructing Config
let content = File.readFrom(Path(xdbPath))
let ver = versionFromHeader(newHeaderFromBytes(content))
if (ver.id != desiredVersion.id) { log.error("xdb is ${ver.name}, config wants ${desiredVersion.name}") } Type guard
func versionMatches(path: String, want: Version): Bool {
let h = newHeaderFromBytes(File.readFrom(Path(path)))
return versionFromHeader(h).id == want.id
} Try / catch
try {
let cfg = Config(policy, ipVersion, xdbPath, poolSize)
} catch (e: Exception) {
if (e.message.contains("version mismatch")) { /* reload correct xdb or fix ipVersion */ }
throw e
} Prevention
- Keep separate config keys for v4/v6 database paths
- Detect the version from the header instead of hardcoding ipVersion
- Name xdb files with their version (ip.v4.xdb / ip.v6.xdb) and check the name
- Verify after every database deploy/upgrade
When it happens
Trigger: Constructing Config with ipVersion = V6 while pointing xdbPath at an IPv4-only .xdb (or vice versa); reusing a config/path constant after switching database files.
Common situations: Deploying the v6 database but leaving the v4 path in the config, upgrading from an IPv4 xdb to an IPv6 one without updating ipVersion, mixing files from different downloads.
Related errors
- incomplete read (${rBytes} read, ${header.HeaderInfoLength}
- invalid structure version ${header.version}
- xdb file exceeds the maximum supported bytes: ${maxFilePtr}
- ip verison not match: xdb file ${xdbFile.getAbsolutePath()}
- invalid structure version {}
AI-assisted analysis of lionsoul2014/ip2region@c1a1fc7d59 (2026-09-02).
Data as JSON: /api/errors/dea2e0fa566dccf4.
Report an issue: GitHub.