{"record":{"id":"6508f3e50cdf2f72","repo":"nodejs/node","slug":"ares-library-init-s-6508f3","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/ahost.c","lineNumber":88,"sourceCode":"  fd_set               write_fds;\n  struct timeval      *tvp;\n  struct timeval       tv;\n  struct in_addr       addr4;\n  struct ares_in6_addr addr6;\n  ares_getopt_state_t  state;\n  char                *servers = NULL;\n\n#ifdef USE_WINSOCK\n  WORD    wVersionRequested = MAKEWORD(USE_WINSOCK, USE_WINSOCK);\n  WSADATA wsaData;\n  WSAStartup(wVersionRequested, &wsaData);\n#endif\n\n  memset(&options, 0, sizeof(options));\n\n  status = ares_library_init(ARES_LIB_INIT_ALL);\n  if (status != ARES_SUCCESS) {\n    fprintf(stderr, \"ares_library_init: %s\\n\", ares_strerror(status));\n    return 1;\n  }\n\n  ares_getopt_init(&state, argc, (const char * const *)argv);\n  while ((c = ares_getopt(&state, \"dt:h?D:s:\")) != -1) {\n    switch (c) {\n      case 'd':\n#ifdef WATT32\n        dbug_init();\n#endif\n        break;\n      case 'D':\n        optmask |= ARES_OPT_DOMAINS;\n        options.ndomains++;\n        options.domains = (char **)realloc(\n          options.domains, (size_t)options.ndomains * sizeof(char *));\n        options.domains[options.ndomains - 1] = strdup(state.optarg);\n        break;","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/deps/cares/src/tools/ahost.c#L70-L106","documentation":"Printed by ahost's main() at ahost.c:88 when ares_library_init(ARES_LIB_INIT_ALL) returns non-success. This is the first c-ares call in ahost, initializing global library state. On Windows it follows WSAStartup. The ares_strerror(status) detail identifies the cause. The tool returns 1 immediately.","triggerScenarios":"Calling ares_library_init(ARES_LIB_INIT_ALL) at line 86 of ahost's main(). Fails on Windows if WSAStartup failed at line 81, if the library was already initialized without cleanup (double-init), or if the c-ares build is missing required platform support. Identical root cause class as adig's error 729.","commonSituations":"c-ares shared library version mismatch between compile-time headers and runtime library. On Windows, WinSock initialization failure due to version or resource issues. A host process that embeds c-ares already called ares_library_init before ahost runs (unlikely for standalone tool, common in embedded scenarios).","solutions":["Check the ares_strerror() output for the specific status code.","On Windows, ensure WSAStartup succeeds — verify the USE_WINSOCK version matches the installed WinSock DLL.","Ensure ares_library_init and ares_library_cleanup are called in matched pairs exactly once.","Rebuild ahost against the same c-ares version to eliminate ABI mismatches."],"exampleFix":"// before: library already initialized by host process\nares_library_init(ARES_LIB_INIT_ALL);  // from another component\n// ahost's main() calls it again -> failure\n\n// after: coordinate init/cleanup across the process\n// call ares_library_init once at process start,\n// ares_library_cleanup once at process exit","handlingStrategy":"validation","validationCode":"// Same pattern as error 729: init exactly once\nstatic int lib_initialized = 0;\nif (!lib_initialized) {\n    int status = ares_library_init(ARES_LIB_INIT_ALL);\n    if (status != ARES_SUCCESS) {\n        fprintf(stderr, \"ares_library_init: %s\\n\", ares_strerror(status));\n        return -1;\n    }\n    lib_initialized = 1;\n}","typeGuard":null,"tryCatchPattern":"status = ares_library_init(ARES_LIB_INIT_ALL);\nif (status != ARES_SUCCESS) {\n    fprintf(stderr, \"ares_library_init: %s\\n\", ares_strerror(status));\n    return EXIT_FAILURE;\n}","preventionTips":["Initialize c-ares exactly once per process with matched cleanup.","On Windows, ensure WSAStartup succeeds before calling ares_library_init.","Use the same c-ares version at compile time and runtime to avoid ABI mismatches."],"tags":["c-ares","ahost","initialization","library-init","critical"],"backgroundTag":null,"analyzedSha":"1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e","analyzedAt":"2026-08-13T00:53:24.642Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}