oven-sh/bun · error

ares_library_init_mem failed

Error message

ares_library_init_mem failed: {}

What it means

One-time c-ares library initialization with mimalloc allocator hooks (ares_library_init_mem) returned a non-success code, so async DNS cannot be initialized. Subsequent DNS resolutions through c-ares will fail; the rc/error is interpolated.

Solutions

  1. Retry the process — initialization failure is usually due to resource exhaustion
  2. Check memory availability since allocator hooks are registered at init
  3. Fall back to Node's threadpool DNS (e.g. unset bun's c-ares path) or use IP addresses directly
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at src/cares_sys/c_ares.rs:965 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of oven-sh/bun@8c5296ac45 (2026-08-16). Data as JSON: /api/errors/f198883453d175f8. Report an issue: GitHub.

Appendix: source

Thrown at src/cares_sys/c_ares.rs:965

            if readable { fd } else { ARES_SOCKET_BAD },
            if writable { fd } else { ARES_SOCKET_BAD },
        );
    }
}

fn library_init() {
    bun_core::run_once! {{
        // SAFETY: c-ares FFI; mimalloc fn pointers have C ABI matching ares_library_init_mem's contract.
        let rc = unsafe {
            ares_library_init_mem(
                ARES_LIB_INIT_ALL,
                Some(bun_alloc::mimalloc::mi_malloc),
                Some(bun_alloc::mimalloc::mi_free),
                Some(bun_alloc::mimalloc::mi_realloc),
            )
        };
        if rc != ARES_SUCCESS {
            panic!("ares_library_init_mem failed: {}", rc);
        }
    }}
}

pub(crate) type ares_callback =
    Option<unsafe extern "C" fn(*mut c_void, c_int, c_int, *mut u8, c_int)>;
pub(crate) type ares_host_callback =
    Option<unsafe extern "C" fn(*mut c_void, c_int, c_int, *mut struct_hostent)>;
pub(crate) type ares_nameinfo_callback =
    Option<unsafe extern "C" fn(*mut c_void, c_int, c_int, *mut u8, *mut u8)>;
pub(crate) type ares_addrinfo_callback =
    unsafe extern "C" fn(*mut c_void, c_int, c_int, *mut AddrInfo);

unsafe extern "C" {
    fn ares_library_init_mem(
        flags: c_int,
        amalloc: Option<unsafe extern "C" fn(usize) -> *mut c_void>,
        afree: Option<unsafe extern "C" fn(*mut c_void)>,

View on GitHub (pinned to 8c5296ac45)