{"record":{"id":"c94460b293cb4e56","repo":"rust-lang/rust","slug":"failed-to-lookup-address-information-detail-c94460","errorCode":null,"errorMessage":"failed to lookup address information: {detail}","messagePattern":"failed to lookup address information: (.+?)","errorType":"exception","errorClass":"io::Error","httpStatus":null,"severity":"error","filePath":"library/std/src/sys/net/connection/socket/unix.rs","lineNumber":59,"sourceCode":"    // We may need to trigger a glibc workaround. See on_resolver_failure() for details.\n    on_resolver_failure();\n\n    #[cfg(not(any(target_os = \"espidf\", target_os = \"nuttx\")))]\n    if err == libc::EAI_SYSTEM {\n        return Err(io::Error::last_os_error());\n    }\n\n    #[cfg(not(any(target_os = \"espidf\", target_os = \"nuttx\")))]\n    let detail = unsafe {\n        // We can't always expect a UTF-8 environment. When we don't get that luxury,\n        // it's better to give a low-quality error message than none at all.\n        CStr::from_ptr(libc::gai_strerror(err)).to_string_lossy()\n    };\n\n    #[cfg(any(target_os = \"espidf\", target_os = \"nuttx\"))]\n    let detail = \"\";\n\n    Err(io::Error::new(\n        io::ErrorKind::Uncategorized,\n        &format!(\"failed to lookup address information: {detail}\")[..],\n    ))\n}\n\nimpl Socket {\n    pub fn new(family: c_int, ty: c_int) -> io::Result<Socket> {\n        cfg_select! {\n            any(\n                target_os = \"android\",\n                target_os = \"dragonfly\",\n                target_os = \"freebsd\",\n                target_os = \"illumos\",\n                target_os = \"hurd\",\n                target_os = \"linux\",\n                target_os = \"netbsd\",\n                target_os = \"openbsd\",\n                target_os = \"cygwin\",","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/rust-lang/rust/blob/7088e4b63a9516ebfbfe2ab2d999cf01a528ac14/library/std/src/sys/net/connection/socket/unix.rs#L41-L77","documentation":"Returned by Rust std's unix getaddrinfo wrapper when libc getaddrinfo reports a failure. It special-cases EAI_SYSTEM (returns last_os_error instead) and otherwise renders libc::gai_strerror(err) as the detail string. On espidf/nuttx the detail is empty. ErrorKind is Uncategorized.","triggerScenarios":"Any DNS resolution that fails on a unix-like target: NXDOMAIN, no resolver configured, /etc/hosts/ resolv.conf missing, temporary resolver outage, unsupported family, or service-name unknown. Reached through to_socket_addrs, TcpStream::connect, UdpSocket::bind with a hostname.","commonSituations":"Container/chroot without /etc/resolv.conf; DNS server down; transient network loss; typo in hostname; IPv6 lookup on IPv4-only host; sandbox blocking the resolver syscall.","solutions":["Inspect the detail string: 'Name or service not known' -> fix hostname; 'Temporary failure in name resolution' -> retry with backoff.","Ensure /etc/resolv.conf and /etc/nsswitch.conf exist and name a reachable nameserver.","Test with `getent hosts <name>` or `dig <name>` to isolate resolver vs application issues.","Fall back to a cached/literal IP address or implement a retry policy for transient failures."],"exampleFix":"// before\nmatch (\"api.example.com\", 443).to_socket_addrs() {\n    Ok(_) => {},\n    Err(e) => panic!(\"{e}\"),\n}\n\n// after\nuse std::time::Duration;\nlet mut last = None;\nfor _ in 0..3 {\n    match (\"api.example.com\", 443).to_socket_addrs() {\n        Ok(it) => { /* use it */ break; }\n        Err(e) => { last = Some(e); std::thread::sleep(Duration::from_secs(2)); }\n    }\n}","handlingStrategy":"retry","validationCode":"fn lookup_with_fallback(host: &str, port: u16) -> io::Result<std::net::SocketAddr> {\n    if let Ok(ip) = host.parse::<std::net::IpAddr>() {\n        return Ok(std::net::SocketAddr::new(ip, port));\n    }\n    (host, port).to_socket_addrs()?.next()\n        .ok_or_else(|| io::Error::new(io::ErrorKind::Uncategorized, \"no addr\"))\n}","typeGuard":null,"tryCatchPattern":"use std::time::Duration;\nlet mut last = None;\nfor _ in 0..3 {\n    match (host, port).to_socket_addrs() {\n        Ok(mut it) => return Ok(it.next().unwrap()),\n        Err(e) if e.to_string().contains(\"Temporary failure\") => {\n            last = Some(e); std::thread::sleep(Duration::from_secs(2));\n        }\n        Err(e) => return Err(e),\n    }\n}\nErr(last.unwrap())","preventionTips":["Ensure /etc/resolv.conf and a reachable nameserver exist in the runtime.","Cache resolved SocketAddrs to avoid repeated lookups.","Retry transient resolver failures with exponential backoff."],"tags":["rust","std","network","unix","dns","socket","getaddrinfo"],"backgroundTag":null,"analyzedSha":"7088e4b63a9516ebfbfe2ab2d999cf01a528ac14","analyzedAt":"2026-08-10T14:17:03.603Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}