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

Add a DNS name resolver #1826

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft

Add a DNS name resolver #1826

wants to merge 6 commits into from

Conversation

glbrntt
Copy link
Collaborator

@glbrntt glbrntt commented Mar 11, 2024

Motivation:

Many users will rely on DNS to resolve the IP addresses of servers to connect to, we should therefore provide a DNS name resolver.

Modifications:

  • Add a DNS name resolver factory capable of resolving IP addresses and service config via TXT records.
  • Add the resolve to the registry defaults

Result:

Can resolve DNS targets

Motivation:

Many users will rely on DNS to resolve the IP addresses of servers to
connect to, we should therefore provide a DNS name resolver.

Modifications:

- Add a DNS name resolver factory capable of resolving IP addresses and
  service config via TXT records.
- Add the resolve to the registry defaults

Result:

Can resolve DNS targets
@glbrntt glbrntt requested a review from gjcairo March 11, 2024 16:34
@glbrntt glbrntt added the v2 A change for v2 label Mar 11, 2024
@glbrntt
Copy link
Collaborator Author

glbrntt commented Mar 11, 2024

Note: we can't merge this until we have a 1.0.0 for swift-async-dns-resolver, however, I'd like to get a review on this in the meantime to make sure we're happy with the shape of this for now.

Comment on lines 113 to 114
/// The hostname of the system the resolver is running on. May be used when a service config
/// from a list of config choices.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: the second sentence sounds wrong, not sure if you meant s/when/with or something else.

Comment on lines 268 to 270
func next() async throws -> NameResolutionResult? {
return try await self.resolve()
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've got some concerns about this conformance to AsyncIteratorProtocol. First of all, this sequence never ends (unless it throws) which I guess is okay. However, the docs say:

After returning nil (or throwing an error) from next(), the iterator enters a terminal state, and all future calls to next() must return nil.

And we're not respecting this, as nothing stops the caller from calling next() again after throwing, and getting a value back.

Secondly, I'm not sure we're dealing with cancellation appropriately. We're not checking whether the task is cancelled nor using a cancellation handler, and we're not returning nil if the task does get cancelled.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've got some concerns about this conformance to AsyncIteratorProtocol. First of all, this sequence never ends (unless it throws) which I guess is okay.

Yeah, there's no requirement for it to end so this part is fine.

However, the docs say:

After returning nil (or throwing an error) from next(), the iterator enters a terminal state, and all future calls to next() must return nil.

And we're not respecting this, as nothing stops the caller from calling next() again after throwing, and getting a value back.

Interesting, I'm not sure how widely we respect this. I'll fix this up though.

Secondly, I'm not sure we're dealing with cancellation appropriately. We're not checking whether the task is cancelled nor using a cancellation handler, and we're not returning nil if the task does get cancelled.

I don't think we need to check explicitly: at the moment we just let calls to the underlying DNS resolver fail with a a cancellation error and have that bubble up.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC the resolver's resolve() method only throws RPCError when calling get() on the Result. We're using a non-throwing TaskGroup in resolveEndpoints() so cancellation can't bubble up via CancellationError.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch!

@glbrntt glbrntt requested a review from gjcairo March 14, 2024 10:57
Copy link
Collaborator

@gjcairo gjcairo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v2 A change for v2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants