Skip to content

DNS lookups should not block the event loop #1724

Description

@n-miles

The Problem

The default name resolver for AHC is:

new DefaultNameResolver(ImmediateEventExecutor.INSTANCE)

This does DNS lookups by using the calling thread (a Netty event loop thread) to do a blocking DNS lookup via the OS mechanism. This is a bad default behavior.

Proposed Solution

I propose that we move the blocking DNS lookups into a separate event loop. There does not appear to be a resolver in Netty that will do this, so we would likely need to create one.

Thoughts?

I am willing to do the development for this if we want this feature.

Activity

  1. TomGranot commented on Aug 23, 2020

    @TomGranot
    Contributor

    @n-miles if this is still relevant, I contacted the repo's maintainer to take over the repo (he's been looking for a new maintainer for a while now).

    If I get the green light I'd be happy to incorporate this feature into the project.

  2. TomGranot commented on Dec 12, 2020

    @TomGranot
    Contributor

    @n-miles Current maintainer. If you'd like we can further discuss this - a proper spec is in order. Let me know if this is still relevant and we can develop the idea further (I don't see why allowing for less blocking is a bad idea, but would have to dig deeper to give a smarter answer).

  3. n-miles commented on May 4, 2021

    @n-miles
    ContributorAuthor

    The main issue with doing this is that there just isn't a mechanism in Java to do async lookups. Netty has resolvers that will hit DNS servers in an async fashion, but presumably most users want to use the normal OS mechanism. The closest approximation I can come up with is a threadpool doing blocking DNS lookups and just not blocking the calling (Netty) threads.

  4. n-miles commented on May 5, 2021

    @n-miles
    ContributorAuthor

    The APIs are there in Linux and Windows at the OS layer, yes. But I don't believe those APIs exist on all OSes that Java supports, so there is not a mechanism to do that in Java.

  5. n-miles commented on May 5, 2021

    @n-miles
    ContributorAuthor

    If you figure out how to do non-blocking DNS lookups using the OS mechanism on the JVM please tell me how you did it

  6. added a commit that references this issue on Apr 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions