[GH-ISSUE #2068] reverse_lookup hangs forever after a small number of loops #869

Closed
opened 2026-03-16 00:40:38 +03:00 by kerem · 0 comments
Owner

Originally created by @hunterwn on GitHub (Oct 17, 2023).
Original GitHub issue: https://github.com/hickory-dns/hickory-dns/issues/2068

Describe the bug
reverse_lookup hangs forever after a small number of loops (around 5 to 15 usually). The function does not produce an error or a valid output but simply blocks the thread.

To Reproduce
Compile this code (with a valid range of ip addresses for your local network)

use std::{net::Ipv4Addr, io};
use std::str::FromStr;
use trust_dns_resolver::TokioAsyncResolver;

async fn async_resolver_lookup(start_ip_str: &str, end_ip_str: &str) -> io::Result<()> {
    let start_ip = match Ipv4Addr::from_str(start_ip_str) {
        Ok(ip) => ip,
        Err(e) => return Err(io::Error::new(io::ErrorKind::InvalidInput, format!("Invalid start IP: {}", e))),
    };
    let end_ip = match Ipv4Addr::from_str(end_ip_str) {
        Ok(ip) => ip,
        Err(e) => return Err(io::Error::new(io::ErrorKind::InvalidInput, format!("Invalid end IP: {}", e))),
    };

    let resolver = TokioAsyncResolver::tokio_from_system_conf().ok().unwrap();

    let mut current_ip = start_ip;
    while current_ip <= end_ip {
        let ip_str = current_ip.to_string();
        let hostnames = resolver.reverse_lookup(current_ip.into()).await;
        match hostnames {
            Ok(hostnames) => {
                for hostname in hostnames.iter() {
                    println!("IP: {}, Hostname: {}", ip_str, hostname.to_utf8());
                }
            }
            Err(e) => {
                println!("Failed to resolve IP {}: {}", ip_str, e);
            }
        }
        let octets = current_ip.octets();
        match u32::from_be_bytes(octets).checked_add(1) {
            Some(new_ip) => current_ip = Ipv4Addr::from(new_ip.to_be_bytes()),
            None => break,
        };
    }

    Ok(())
}

#[tokio::main]
async fn main() {
    match async_resolver_lookup("192.168.0.1", "192.168.0.255").await {
        Ok(_) => println!("Lookup completed"),
        Err(e) => eprintln!("Lookup failed: {}", e),
    }
}

Expected behavior
The reverse_lookup function either returns a valid response or produces an error after a short period of time.

System:

  • OS: Windows 10
  • Architecture: x86_64
  • Version: 22H2 Os Build 19045.2913
  • rustc version: 1.73.0

Version:
Crate: resolver
Version: 0.23.1

Originally created by @hunterwn on GitHub (Oct 17, 2023). Original GitHub issue: https://github.com/hickory-dns/hickory-dns/issues/2068 **Describe the bug** reverse_lookup hangs forever after a small number of loops (around 5 to 15 usually). The function does not produce an error or a valid output but simply blocks the thread. **To Reproduce** Compile this code (with a valid range of ip addresses for your local network) ``` use std::{net::Ipv4Addr, io}; use std::str::FromStr; use trust_dns_resolver::TokioAsyncResolver; async fn async_resolver_lookup(start_ip_str: &str, end_ip_str: &str) -> io::Result<()> { let start_ip = match Ipv4Addr::from_str(start_ip_str) { Ok(ip) => ip, Err(e) => return Err(io::Error::new(io::ErrorKind::InvalidInput, format!("Invalid start IP: {}", e))), }; let end_ip = match Ipv4Addr::from_str(end_ip_str) { Ok(ip) => ip, Err(e) => return Err(io::Error::new(io::ErrorKind::InvalidInput, format!("Invalid end IP: {}", e))), }; let resolver = TokioAsyncResolver::tokio_from_system_conf().ok().unwrap(); let mut current_ip = start_ip; while current_ip <= end_ip { let ip_str = current_ip.to_string(); let hostnames = resolver.reverse_lookup(current_ip.into()).await; match hostnames { Ok(hostnames) => { for hostname in hostnames.iter() { println!("IP: {}, Hostname: {}", ip_str, hostname.to_utf8()); } } Err(e) => { println!("Failed to resolve IP {}: {}", ip_str, e); } } let octets = current_ip.octets(); match u32::from_be_bytes(octets).checked_add(1) { Some(new_ip) => current_ip = Ipv4Addr::from(new_ip.to_be_bytes()), None => break, }; } Ok(()) } #[tokio::main] async fn main() { match async_resolver_lookup("192.168.0.1", "192.168.0.255").await { Ok(_) => println!("Lookup completed"), Err(e) => eprintln!("Lookup failed: {}", e), } } ``` **Expected behavior** The reverse_lookup function either returns a valid response or produces an error after a short period of time. **System:** - OS: Windows 10 - Architecture: x86_64 - Version: 22H2 Os Build 19045.2913 - rustc version: 1.73.0 **Version:** Crate: resolver Version: 0.23.1
kerem closed this issue 2026-03-16 00:40:43 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/hickory-dns#869
No description provided.