Skip to content

InternetAddress.lookup needs a cache #59652

Open
@gmpassos

Description

@gmpassos

The method InternetAddress.lookup needs a resolution cache:

external static Future<List<InternetAddress>> lookup(

Why?

For each connection requiring hostname resolution, a new lookup is performed. This triggers requests to the OS DNS resolver (e.g., bind, dnsmasq, mDNSResponder, etc.). Depending on the application being developed, this behavior can overwhelm the OS.

For instance, while benchmarking shelf with intensive requests, this behavior "crashed" the macOS DNS responder. Additionally, the hostname lookup accounted for a significant portion of the time in each benchmark interaction, resulting in non-performant behavior.

Suggestion

I suggest introducing an InternetAddressOverrides, similar to HttpOverrides, and akin to what Java does with InetAddress.

With this feature, developers could customize how their application handles DNS resolution without needing to modify the code that creates a Socket (which may not always be accessible for changes). Whether the default behavior includes a cached lookup would depend on the Dart team's decision, but an InternetAddressOverrides would empower developers to choose the best behavior for their specific applications.

Example

To work around this issue, I have created tools that allow cached addresses for HTTP requests:
https://github.com/gmpassos/multi_domain_secure_server/blob/master/lib/src/connector_tools.dart#L7

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-vmUse area-vm for VM related issues, including code coverage, and the AOT and JIT backends.closed-not-plannedClosed as we don't intend to take action on the reported issuelibrary-iotriagedIssue has been triaged by sub teamtype-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions