Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the name resolver interface #2603

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

baarde
Copy link

@baarde baarde commented Dec 4, 2023

This commit adds NIOStreamingResolver as a replacement for Resolver. This resolver is phrased in terms of resolving names to socket addresses, whithout any implication that DNS will be used. It also removes constraints on how results should be delivered, allowing an implementation to stream results as they arrive, without having to wait for a complete response.

Motivation:

Hello, I'm currently in need of a custom resolver for my HTTP client. But before opening a PR to add a Resolver to AsyncHTTPClient, I'd like to address the issues exposed by @Lukasa in #1487:

This Resolver interface bakes has two major limitations. The first is that it bakes in a strong knowledge of DNS: it's phrased in terms of A/AAAA. The second is that it does not allow result streaming: there are only two opportunities to deliver results.

So I've implemented the proposed interface.

Modifications:

This PR adds the proposed NIOStreamingResolver protocol and its associated NIONameResolutionSession.

HappyEyeballsConnector and GetaddrinfoResolver are updated to uses this new interface.

The Resolver interface is deprecated. The NIOResolverToStreamingResolver adapter is used to maintain compatibility with the existing implementations.

Name resolution tests are left mostly unchanged for the moment.

Result:

  • The default name resolution is unchanged.
  • Client using the Resolver protocol will get a deprecation warning.
  • Implementations of the Resolver protocol may observe a minor change: if the connection to the target socket address succeeds or fails instantly (as sometimes happens when using EmbeddedChannel instead of the real network), the cancelQueries method may be called even though both A and AAAA queries have already completed. This is because the resolver delivering results and the resolver completing are now two separate events, and HappyEyeballsConnector may terminate and clean up its resources between the two events. This can be seen in testIPv6OnlyResolution and testAQueryReturningFirstThenAAAAReturns. However it is unlikely to have an impact in the real world as the cancelQueries method is probably always ignored.

Unresolved:

  • I haven't implemented the proposed NIONameResolutionSession.Hints type as neither HappyEyeballsConnector nor GetaddrinfoResolver would currently use it. Do we want it now? Or should we wait until we have a real use for it?
  • I haven't added new tests yet, nor modified existing ones (beyond what was strictly necessary to make them pass). I'd like to make sure every one is happy with the new design first.
  • Streaming results will break Happy Eyeball's expectation that results be sorted according to RFC 6724. At some point we will have to sort the results in HappyEyeballsConnector. But I think we can address that later.
  • Should we make NIOStreamingResolver Sendable?

@baarde baarde marked this pull request as draft December 6, 2023 10:02
@baarde baarde changed the title WIP: Update the name resolver interface Update the name resolver interface Dec 6, 2023
@baarde baarde marked this pull request as ready for review December 6, 2023 16:35
@baarde baarde force-pushed the streaming-resolver branch from ea058aa to 383702b Compare December 6, 2023 16:36
This commit adds `NIOStreamingResolver` as a replacement for `Resolver`. This resolver is phrased in terms of resolving names to socket addresses, whithout any implication that DNS will be used. It also removes constraints on how results should be delivered, allowing an implementation to stream results as they arrive, without having to wait for a complete response.
@baarde baarde force-pushed the streaming-resolver branch from 383702b to f4ab14f Compare January 29, 2024 10:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant