Description
The method InternetAddress.lookup
needs a resolution cache:
Line 152 in c6daa6a
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