{"record":{"id":"8d51cd01f05943c3","repo":"lionsoul2014/ip2region","slug":"failed-to-load-xdb-content-s","errorCode":null,"errorMessage":"failed to load xdb content: %s","messagePattern":"failed to load xdb content: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"binding/nginx/src/ngx_http_ip2region_module.c","lineNumber":189,"sourceCode":"            }\n            return NGX_CONF_ERROR;\n        }\n\n        err = xdb_new_with_vector_index(xdb_version, &ip2region_searcher->searcher, db_path, ip2region_searcher->v_index);\n        xdb_free_header((void *)header);\n        if (err != 0) {\n            ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n                               \"failed to create vector index cached searcher: %s\", db_path);\n            xdb_free_vector_index((void *)ip2region_searcher->v_index);\n            if(ngx_http_ip2region_is_absolute_path(db_name) != NGX_OK) {\n                free(db_path);\n            }\n            return NGX_CONF_ERROR;\n        }\n    } else if (strcmp(cache_policy, \"content\") == 0) {\n        ip2region_searcher->c_buffer = xdb_load_content_from_file(db_path);\n        if (ip2region_searcher->c_buffer == NULL) {\n            ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n                               \"failed to load xdb content: %s\", db_path);\n            xdb_free_header((void *)header);\n            if(ngx_http_ip2region_is_absolute_path(db_name) != NGX_OK) {\n                free(db_path);\n            }\n            return NGX_CONF_ERROR;\n        }\n\n        err = xdb_new_with_buffer(xdb_version, &ip2region_searcher->searcher, ip2region_searcher->c_buffer);\n        xdb_free_header((void *)header);\n        if (err != 0) {\n            ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n                               \"failed to create content cached searcher: %s\", db_path);\n            xdb_free_content((void *)ip2region_searcher->c_buffer);\n            if(ngx_http_ip2region_is_absolute_path(db_name) != NGX_OK) {\n                free(db_path);\n            }\n            return NGX_CONF_ERROR;","sourceCodeStart":171,"sourceCodeEnd":207,"githubUrl":"https://github.com/lionsoul2014/ip2region/blob/c1a1fc7d5941760db3f8431dc05c48cf7f0e30a1/binding/nginx/src/ngx_http_ip2region_module.c#L171-L207","documentation":"With cache_policy \"content\", the module loads the entire xdb into memory via xdb_load_content_from_file. NULL means the whole-file read or its memory allocation failed, so no content-cached searcher can be created.","triggerScenarios":"xdb_load_content_from_file returns NULL: the file is unreadable (permissions), shorter than the content length declared in its header (truncated), or malloc of the full xdb size failed.","commonSituations":"Large xdb (hundreds of MB) under a low cgroup/container memory limit; truncated download; unreadable path for the worker user; file replaced mid-load.","solutions":["Check available memory (`free -m` / container limits) — the full xdb must fit in RAM; raise the limit or pick policy \"file\" or \"vectorIndex\".","Re-download and verify the xdb file size/checksum to rule out truncation.","Verify the nginx worker user can read the file.","If RAM is tight, switch ip2region_cache_policy to \"vectorIndex\" or \"file\"."],"exampleFix":"ip2region_cache_policy content;\n# after (low memory environment)\nip2region_cache_policy vectorIndex;","handlingStrategy":"validation","validationCode":"#!/bin/bash\nf=/data/ip2region.xdb\nsize=$(stat -c%s \"$f\")\navail=$(free -m | awk 'NR==2{print $7}')\n[ $((size/1024/1024)) -lt $avail ] && echo \"OK: xdb ($((size/1024/1024))MB) fits in ${avail}MB free\" || echo \"WARN: content policy needs $((size/1024/1024))MB RAM\"\nsha256sum -c ip2region.xdb.sha256 || echo \"xdb corrupt/truncated\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Before choosing \"content\" policy, confirm the whole xdb fits comfortably in RAM.","Checksum-verify every xdb download.","Set container memory limits above xdb size + headroom.","Prefer \"vectorIndex\" on small-memory hosts."],"tags":["nginx","xdb","memory","content-cache","file-io"],"backgroundTag":"xdb-load-out-of-memory","analyzedSha":"c1a1fc7d5941760db3f8431dc05c48cf7f0e30a1","analyzedAt":"2026-09-02T16:58:39.988Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}