{"record":{"id":"e60bfe416547036e","repo":"nodejs/node","slug":"ares-library-init-s","errorCode":null,"errorMessage":"ares_library_init: %s\n","messagePattern":"ares_library_init: (.+?)\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"deps/cares/src/tools/adig.c","lineNumber":1497,"sourceCode":"    global_config.options.ndomains  = 1;\n  }\n}\n\nint main(int argc, char **argv)\n{\n  ares_channel_t *channel = NULL;\n  ares_status_t   status;\n  int             rv = 0;\n\n#ifdef USE_WINSOCK\n  WORD    wVersionRequested = MAKEWORD(USE_WINSOCK, USE_WINSOCK);\n  WSADATA wsaData;\n  WSAStartup(wVersionRequested, &wsaData);\n#endif\n\n  status = (ares_status_t)ares_library_init(ARES_LIB_INIT_ALL);\n  if (status != ARES_SUCCESS) {\n    fprintf(stderr, \"ares_library_init: %s\\n\", ares_strerror((int)status));\n    return 1;\n  }\n\n  config_defaults();\n\n  if (!read_cmdline(argc, (const char * const *)argv, 1)) {\n    printf(\"\\n** ERROR: %s\\n\\n\", global_config.error);\n    print_help();\n    rv = 1;\n    goto done;\n  }\n\n  if (global_config.no_rcfile && !read_rcfile()) {\n    fprintf(stderr, \"\\n** ERROR: %s\\n\", global_config.error);\n  }\n\n  if (global_config.is_help) {\n    print_help();","sourceCodeStart":1479,"sourceCodeEnd":1515,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/deps/cares/src/tools/adig.c#L1479-L1515","documentation":"Printed by adig's main() at adig.c:1497 when ares_library_init(ARES_LIB_INIT_ALL) returns a status other than ARES_SUCCESS. This call initializes the c-ares library's global state (including WinSock startup on Windows). The error string from ares_strerror() is included. The tool returns 1 immediately — no channel is created, no queries are issued.","triggerScenarios":"Calling ares_library_init(ARES_LIB_INIT_ALL) at the start of adig's main() (line 1496). Fails when the library cannot initialize its internal subsystems — on Windows if WSAStartup failed earlier (line 1488), or if the library was compiled without required features. Also fails if ares_library_init has already been called without a matching ares_library_cleanup (double-init).","commonSituations":"On Windows, WSAStartup fails due to a WinSock version mismatch or resource limitation. The c-ares shared library version is incompatible with the headers the tool was compiled against. The library was built with ARES_LIB_INIT_ALL but the platform lacks a required init component. Another part of the application already called ares_library_init.","solutions":["Check the ares_strerror() output in the message to identify the specific failure code (e.g., ARES_EFORMERR for internal format errors).","On Windows, verify that WSAStartup succeeded — check the USE_WINSOCK version constant matches the installed WinSock.","Ensure ares_library_init is called exactly once per process (or use reference counting) and matched with ares_library_cleanup.","Rebuild adig and c-ares from the same source version to avoid ABI mismatches."],"exampleFix":"// before: double-init or version mismatch\nares_library_init(ARES_LIB_INIT_ALL);  // first call (e.g., in another lib)\n// adig's main() calls ares_library_init again\n// -> 'ares_library_init: ...'\n\n// after: init once, cleanup once\nstatus = ares_library_init(ARES_LIB_INIT_ALL);\nif (status != ARES_SUCCESS) { /* handle */ }\n// ... use c-ares ...\nares_library_cleanup();  // exactly once at shutdown","handlingStrategy":"validation","validationCode":"// Call ares_library_init exactly once per process\nstatic int lib_initialized = 0;\nif (!lib_initialized) {\n    ares_status_t status = (ares_status_t)ares_library_init(ARES_LIB_INIT_ALL);\n    if (status != ARES_SUCCESS) {\n        fprintf(stderr, \"init failed: %s\\n\", ares_strerror((int)status));\n        return -1;\n    }\n    lib_initialized = 1;\n}\n// at process exit: ares_library_cleanup();","typeGuard":null,"tryCatchPattern":"ares_status_t status = (ares_status_t)ares_library_init(ARES_LIB_INIT_ALL);\nif (status != ARES_SUCCESS) {\n    fprintf(stderr, \"ares_library_init: %s\\n\", ares_strerror((int)status));\n    // do not proceed to channel creation; exit or fall back\n    return EXIT_FAILURE;\n}","preventionTips":["Initialize c-ares exactly once per process and clean up exactly once at exit.","Match c-ares header version with the linked shared library.","On Windows, verify WSAStartup succeeds before calling ares_library_init."],"tags":["c-ares","adig","initialization","library-init","critical"],"backgroundTag":null,"analyzedSha":"1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e","analyzedAt":"2026-08-13T00:53:24.642Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}