nodejs/node · critical

ares_library_init: %s

Error message

ares_library_init: %s

What it means

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.

Source

Thrown at deps/cares/src/tools/ahost.c:88

  fd_set               write_fds;
  struct timeval      *tvp;
  struct timeval       tv;
  struct in_addr       addr4;
  struct ares_in6_addr addr6;
  ares_getopt_state_t  state;
  char                *servers = NULL;

#ifdef USE_WINSOCK
  WORD    wVersionRequested = MAKEWORD(USE_WINSOCK, USE_WINSOCK);
  WSADATA wsaData;
  WSAStartup(wVersionRequested, &wsaData);
#endif

  memset(&options, 0, sizeof(options));

  status = ares_library_init(ARES_LIB_INIT_ALL);
  if (status != ARES_SUCCESS) {
    fprintf(stderr, "ares_library_init: %s\n", ares_strerror(status));
    return 1;
  }

  ares_getopt_init(&state, argc, (const char * const *)argv);
  while ((c = ares_getopt(&state, "dt:h?D:s:")) != -1) {
    switch (c) {
      case 'd':
#ifdef WATT32
        dbug_init();
#endif
        break;
      case 'D':
        optmask |= ARES_OPT_DOMAINS;
        options.ndomains++;
        options.domains = (char **)realloc(
          options.domains, (size_t)options.ndomains * sizeof(char *));
        options.domains[options.ndomains - 1] = strdup(state.optarg);
        break;

View on GitHub (pinned to 1b2de5e052)

Solutions

  1. Check the ares_strerror() output for the specific status code.
  2. On Windows, ensure WSAStartup succeeds — verify the USE_WINSOCK version matches the installed WinSock DLL.
  3. Ensure ares_library_init and ares_library_cleanup are called in matched pairs exactly once.
  4. Rebuild ahost against the same c-ares version to eliminate ABI mismatches.

Example fix

// before: library already initialized by host process
ares_library_init(ARES_LIB_INIT_ALL);  // from another component
// ahost's main() calls it again -> failure

// after: coordinate init/cleanup across the process
// call ares_library_init once at process start,
// ares_library_cleanup once at process exit
Defensive patterns

Strategy: validation

Validate before calling

// Same pattern as error 729: init exactly once
static int lib_initialized = 0;
if (!lib_initialized) {
    int status = ares_library_init(ARES_LIB_INIT_ALL);
    if (status != ARES_SUCCESS) {
        fprintf(stderr, "ares_library_init: %s\n", ares_strerror(status));
        return -1;
    }
    lib_initialized = 1;
}

Try / catch

status = ares_library_init(ARES_LIB_INIT_ALL);
if (status != ARES_SUCCESS) {
    fprintf(stderr, "ares_library_init: %s\n", ares_strerror(status));
    return EXIT_FAILURE;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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).

Related errors


AI-assisted analysis of nodejs/node@1b2de5e052 (2026-08-13). Data as JSON: /api/errors/6508f3e50cdf2f72. Report an issue: GitHub.