{"record":{"id":"7b49302a421871cf","repo":"shadowsocks/shadowsocks-rust","slug":"initialize-dns-resolver-with-config-failed-error","errorCode":null,"errorMessage":"initialize DNS resolver with config failed, error: {}","messagePattern":"initialize DNS resolver with config failed, error: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/shadowsocks/src/dns_resolver/hickory_dns_resolver.rs","lineNumber":164,"sourceCode":"            if let Some(opts) = opts {\n                *builder.options_mut() = opts;\n            }\n            let resolver_opts = builder.options_mut();\n\n            // Use Ipv4AndIpv6 strategy. Because Ipv4ThenIpv6 or Ipv6ThenIpv4 will return if the first query returned.\n            // Since we want to use Happy Eyeballs to connect to both IPv4 and IPv6 addresses, we need both A and AAAA records.\n            resolver_opts.ip_strategy = LookupIpStrategy::Ipv4AndIpv6;\n\n            // Enable EDNS0 for large records\n            resolver_opts.edns0 = true;\n\n            trace!(\"initializing DNS resolver with opts {:?}\", resolver_opts);\n\n            match builder.build() {\n                Ok(resolver) => Ok(resolver),\n                Err(err) => {\n                    error!(\"initialize DNS resolver with config failed, error: {}\", err);\n                    Err(io::Error::new(io::ErrorKind::Other, err))\n                }\n            }\n        }\n\n        // To make this independent, if targeting macOS, BSD, Linux, or Windows, we can use the system's configuration\n        // Android doesn't have /etc/resolv.conf.\n        None => {\n            match DnsResolver::builder(ShadowDnsRuntimeProvider::new(connect_opts)) {\n                Ok(mut builder) => {\n                    let opts = builder.options_mut();\n                    // NOTE: timeout will be set by config (for example, /etc/resolv.conf on UNIX-like system)\n                    //\n                    // Only ip_strategy should be changed. Why Ipv4AndIpv6? See comments above.\n                    opts.ip_strategy = LookupIpStrategy::Ipv4AndIpv6;\n\n                    // Enable EDNS0 for large records\n                    opts.edns0 = true;\n","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/shadowsocks/shadowsocks-rust/blob/8eb0f0a65b1d976ab6bed5787327ef86529b0435/crates/shadowsocks/src/dns_resolver/hickory_dns_resolver.rs#L146-L182","documentation":"create_resolver builds a hickory-dns (trust-dns) resolver from explicit name-server config; when builder.build() fails (e.g. no valid name servers after filtering, invalid configuration), the error is logged and re-wrapped as io::ErrorKind::Other. Message text is \"initialize DNS resolver with config failed, error: {inner}\".","triggerScenarios":"Calling hickory_resolver / hickory_dns_system_resolver / hickory_dns_notify_update_dns where the explicitly provided nameserver config (ips, ports, trust anchors, opts) fails hickory's build validation — commonly zero usable name servers or invalid server addresses.","commonSituations":"Config file with malformed or empty nameservers list; all nameservers filtered out (e.g. IPv6 servers on IPv4-only host); invalid DNS port or bogus IP strings in dns config.","solutions":["Check the inner error in the log line to see the underlying hickory failure","Ensure at least one valid, reachable nameserver IP:port is present in the DNS config","Fix malformed nameserver entries (valid IPs, port 53/853) in the configuration","Enable system-config resolution instead of manual config if /etc/resolv.conf or OS settings are usable"],"exampleFix":"// before\nns: [\"999.999.1.1:53\"]\n// after\nns: [\"8.8.8.8:53\", \"1.1.1.1:53\"]","handlingStrategy":"fallback","validationCode":"let ns: Vec<_> = cfg.nameservers.iter().filter(|n| n.parse::<std::net::SocketAddr>().is_ok()).collect();\nif ns.is_empty() { return Err(anyhow!(\"no valid nameservers configured\")); }","typeGuard":null,"tryCatchPattern":"match create_resolver(opts).await {\n    Err(e) if e.kind() == io::ErrorKind::Other => {\n        log::error!(\"resolver init failed: {e}; falling back to public DNS\");\n        create_resolver_with_fallback_dns().await?\n    }\n    other => other?,\n}","preventionTips":["Validate nameserver IPs/ports at config load","Keep at least one known-good fallback resolver (e.g. 8.8.8.8)","Read the logged inner error — it names the exact hickory build failure"],"tags":["dns","resolver","hickory"],"backgroundTag":"module-init-failed","analyzedSha":"8eb0f0a65b1d976ab6bed5787327ef86529b0435","analyzedAt":"2026-09-09T12:20:43.168Z","contentChangedAt":"2026-09-09T12:20:43.168Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}