rust-lang/rust · error · io::Error

failed to lookup address information: {msg}

Error message

failed to lookup address information: {msg}

What it means

Thrown by Rust std's SOLID-OS getaddrinfo wrapper cvt_gai for any non-zero gai error code. It maps well-known codes (EAI_NONAME, EAI_SERVICE, EAI_FAIL, EAI_MEMORY, EAI_FAMILY) to human-readable sub-messages; any unrecognized code falls back to printing the numeric error. ErrorKind is Uncategorized.

Source

Thrown at library/std/src/sys/net/connection/socket/solid.rs:59

pub fn cvt<T: IsMinusOne>(t: T) -> io::Result<T> {
    if t.is_minus_one() { Err(last_error()) } else { Ok(t) }
}

/// A variant of `cvt` for `getaddrinfo` which return 0 for a success.
pub fn cvt_gai(err: c_int) -> io::Result<()> {
    if err == 0 {
        Ok(())
    } else {
        let msg: &dyn crate::fmt::Display = match err {
            netc::EAI_NONAME => &"name or service not known",
            netc::EAI_SERVICE => &"service not supported",
            netc::EAI_FAIL => &"non-recoverable failure in name resolution",
            netc::EAI_MEMORY => &"memory allocation failure",
            netc::EAI_FAMILY => &"family not supported",
            _ => &err,
        };
        Err(io::Error::new(
            io::ErrorKind::Uncategorized,
            &format!("failed to lookup address information: {msg}")[..],
        ))
    }
}

/// Just to provide the same interface as sys/pal/unix/net.rs
pub fn cvt_r<T, F>(mut f: F) -> io::Result<T>
where
    T: IsMinusOne,
    F: FnMut() -> T,
{
    cvt(f())
}

/// Returns the last error from the network subsystem.
fn last_error() -> io::Error {
    io::Error::from_raw_os_error(unsafe { netc::SOLID_NET_GetLastError() })

View on GitHub (pinned to 7088e4b63a)

Solutions

  1. Match the embedded sub-message: 'name or service not known' -> fix hostname; 'family not supported' -> use IPv4; 'service not supported' -> use a numeric port.
  2. Confirm the SOLID network subsystem and DNS resolver are initialized before the lookup.
  3. Prefer literal IP and numeric port to avoid the resolver path entirely.
  4. Log the numeric err value when the message falls through to the default arm.

Example fix

// before
let s = TcpStream::connect("svc.example.com:https")?;

// after
let addr: SocketAddr = ([10,0,0,5], 443).into();
let s = TcpStream::connect(addr)?;
Defensive patterns

Strategy: validation

Validate before calling

fn safe_lookup(host: &str, port: u16) -> io::Result<std::net::SocketAddr> {
    if let Ok(ip) = host.parse::<std::net::IpAddr>() {
        return Ok(std::net::SocketAddr::new(ip, port));
    }
    (host, port).to_socket_addrs()?.next()
        .ok_or_else(|| io::Error::new(io::ErrorKind::Uncategorized, "no addr"))
}

Try / catch

match (host, port).to_socket_addrs() {
    Ok(mut it) => Ok(it.next().unwrap()),
    Err(e) => {
        let msg = e.to_string();
        if msg.contains("family not supported") { /* switch family */ }
        else if msg.contains("name or service not known") { /* fix host */ }
        Err(e)
    }
}

Prevention

When it happens

Trigger: DNS or service-name resolution failing on the SOLID real-time OS: unknown hostname (EAI_NONAME), unsupported service (EAI_SERVICE), non-recoverable resolver failure (EAI_FAIL), memory exhaustion (EAI_MEMORY), or unsupported address family (EAI_FAMILY). Reached via to_socket_addrs and the connect/bind family.

Common situations: Embedded/RTOS deployment on SOLID with no DNS server reachable; specifying a service name not in /etc/services equivalent; requesting IPv6 on an IPv4-only SOLID stack; typo in hostname.

Related errors


AI-assisted analysis of rust-lang/rust@7088e4b63a (2026-08-10). Data as JSON: /api/errors/b1fdee5a200d21c1. Report an issue: GitHub.