Skip to content

DNS resolution happens before connection pool lookup #6444

@yzfeng2020

Description

@yzfeng2020

Summary

The current implementation resolves (it may hit cache, though) DNS for every request before checking the connection pool, which can introduce unnecessary DNS queries even when pooled connections are available.

Expected behavior

Ideally, the client should:

  1. Check the connection pool for an existing connection, ie using the hostname
  2. Only resolve DNS if no pooled connection exists

This would minimize DNS queries, and in other words, only resolving DNS when needing to create new connections.

Actual behavior

Currently in HttpClientDelegate.execute():

  1. DNS resolution happens first (if endpoint.hasIpAddr() returns false)
  2. Then connection pool lookup occurs with the resolved IP

See:

if (endpointWithPort.hasIpAddr() ||
proxyConfig.proxyType().isForwardProxy()) {
// There is no need to resolve the IP address either because it is already known,
// or it isn't needed for forward proxies.
acquireConnectionAndExecute(ctx, endpointWithPort, req, res, timingsBuilder, proxyConfig);
} else {
resolveAddress(endpointWithPort, ctx, (resolved, cause) -> {
timingsBuilder.dnsResolutionEnd();
if (cause == null) {
assert resolved != null;
acquireConnectionAndExecute(ctx, resolved, req, res, timingsBuilder, proxyConfig);
} else {
earlyCancelRequest(cause, ctx, timingsBuilder);
}
});

Why this is a problem

This means:

  • Every request must resolve DNS
  • It may create high load to the DNS server, even with DNS cache or refresh

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