[GH-ISSUE #2110] AsyncResolver mode , override RuntimeProvider , if take a little time in function bind_udp , so this function will be called many times repeatedly #890

Closed
opened 2026-03-16 00:45:54 +03:00 by kerem · 5 comments
Owner

Originally created by @oujl on GitHub (Dec 12, 2023).
Original GitHub issue: https://github.com/hickory-dns/hickory-dns/issues/2110

Describe the bug
I am developing an Android app that uses Hickory DNS. I need to handle the fd special after the UDP socket in DNS. I overloaded the RuntimeProvider, and then I found that it caused a lot of UDP sockets to be created

To Reproduce
override RuntimeProvider , take a little time in function bind_udp , so this function will be called many times repeatedly

Expected behavior
A clear and concise description of what you expected to happen.

System:

  • OS: [android]
  • Architecture: [arm64]
  • Version [12]
  • rustc version: [1.74.1]

Version:
Crate: [resolver]
Version: [0.24.0]

Additional context
Add any other context about the problem here.

Originally created by @oujl on GitHub (Dec 12, 2023). Original GitHub issue: https://github.com/hickory-dns/hickory-dns/issues/2110 **Describe the bug** I am developing an Android app that uses Hickory DNS. I need to handle the fd special after the UDP socket in DNS. I overloaded the RuntimeProvider, and then I found that it caused a lot of UDP sockets to be created **To Reproduce** override RuntimeProvider , take a little time in function bind_udp , so this function will be called many times repeatedly **Expected behavior** A clear and concise description of what you expected to happen. **System:** - OS: [android] - Architecture: [arm64] - Version [12] - rustc version: [1.74.1] **Version:** Crate: [resolver] Version: [0.24.0] **Additional context** Add any other context about the problem here.
kerem closed this issue 2026-03-16 00:45:59 +03:00
Author
Owner

@oujl commented on GitHub (Dec 12, 2023):

test code like this :

impl RuntimeProvider for XXXRuntimeProvider {
type Handle = TokioHandle;
type Timer = TokioTime;
type Udp = TokioUdpSocket;
type Tcp = AsyncIoTokioAsStd;

    fn create_handle(&self) -> Self::Handle {
        self.0.clone()
    }

    fn connect_tcp(
        &self,
        server_addr: SocketAddr,
    ) -> Pin<Box<dyn Send + Future<Output = std::io::Result<Self::Tcp>>>> {
        Box::pin(async move {
            TokioTcpStream::connect(server_addr)
                .await
                .map(AsyncIoTokioAsStd)
        })
    }

    fn bind_udp(
        &self,
        local_addr: SocketAddr,
        _server_addr: SocketAddr,
    ) -> Pin<Box<dyn Send + Future<Output = std::io::Result<Self::Udp>>>> {
        log::debug!(" DNS UDP bind {} -> {}",local_addr,_server_addr);
        Box::pin(async move {
            tokio::time::sleep(std::time::Duration::from_secs(1)).await;
            let udp = tokio::net::UdpSocket::bind(local_addr).await?;
            Ok(udp)
        })
    }
}
<!-- gh-comment-id:1851538555 --> @oujl commented on GitHub (Dec 12, 2023): test code like this : impl RuntimeProvider for XXXRuntimeProvider { type Handle = TokioHandle; type Timer = TokioTime; type Udp = TokioUdpSocket; type Tcp = AsyncIoTokioAsStd<TokioTcpStream>; fn create_handle(&self) -> Self::Handle { self.0.clone() } fn connect_tcp( &self, server_addr: SocketAddr, ) -> Pin<Box<dyn Send + Future<Output = std::io::Result<Self::Tcp>>>> { Box::pin(async move { TokioTcpStream::connect(server_addr) .await .map(AsyncIoTokioAsStd) }) } fn bind_udp( &self, local_addr: SocketAddr, _server_addr: SocketAddr, ) -> Pin<Box<dyn Send + Future<Output = std::io::Result<Self::Udp>>>> { log::debug!(" DNS UDP bind {} -> {}",local_addr,_server_addr); Box::pin(async move { tokio::time::sleep(std::time::Duration::from_secs(1)).await; let udp = tokio::net::UdpSocket::bind(local_addr).await?; Ok(udp) }) } }
Author
Owner

@djc commented on GitHub (Dec 12, 2023):

Yes, it creates a lot of UDP sockets, and for good reason (it would otherwise be too easy for a MITM attack to spoof DNS responses). Given that you didn't fill out the "Expected behavior" section it's unclear why this is causing an issue for you/what we should do differently.

<!-- gh-comment-id:1851564761 --> @djc commented on GitHub (Dec 12, 2023): Yes, it creates a lot of UDP sockets, and for good reason (it would otherwise be too easy for a MITM attack to spoof DNS responses). Given that you didn't fill out the "Expected behavior" section it's unclear why this is causing an issue for you/what we should do differently.
Author
Owner

@oujl commented on GitHub (Dec 12, 2023):

I am writing a VPN type app. Internally, it is necessary to distinguish between proxy traffic and non proxy traffic. I need to label the sockets for proxy traffic before sending data. On Android, it is VpnService # protect Android and Native use local socket communication. Every time DNS resolve is executed, many UDP sockets are created Each socket fd needs to be passed to Android VpnService through the local socket Sometimes I can't handle it. So is there any other API that can avoid creating so many UDP sockets

<!-- gh-comment-id:1851639293 --> @oujl commented on GitHub (Dec 12, 2023): I am writing a VPN type app. Internally, it is necessary to distinguish between proxy traffic and non proxy traffic. I need to label the sockets for proxy traffic before sending data. On Android, it is VpnService # protect Android and Native use local socket communication. Every time DNS resolve is executed, many UDP sockets are created Each socket fd needs to be passed to Android VpnService through the local socket Sometimes I can't handle it. So is there any other API that can avoid creating so many UDP sockets
Author
Owner

@djc commented on GitHub (Dec 12, 2023):

IIRC there currently is not. Perhaps you can avoid relying on UDP in your configuration?

<!-- gh-comment-id:1851700530 --> @djc commented on GitHub (Dec 12, 2023): IIRC there currently is not. Perhaps you can avoid relying on UDP in your configuration?
Author
Owner

@oujl commented on GitHub (Dec 12, 2023):

OK。Thank you for your answer

<!-- gh-comment-id:1851714030 --> @oujl commented on GitHub (Dec 12, 2023): OK。Thank you for your answer
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#890
No description provided.