Add AsyncResolverBuilder and option to overide a pre-created cache #1923
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds the ability to share a DNS Cache between different
AsyncResolver
s. It also add anAsyncResolverBuilder
to avoid adding yet morenew_with_...
methods to theAsyncResolver
.The rough reasoning behind it was that we've got a few different threads running all of which need to make DNS requests, but we didn't want to be making unnecessary requests if we've already done a previous lookup; hence a desire for multiple
AsyncResolver
s to shared their cache.Since we did this work initially, I've thought that perhaps we could just have each thread use a
clone
of an initialAsyncResolver
, which would mean that they shared the cache, since it's anArc
, so perhaps this change is unnecessary?So I guess I have a question for reviewers:
Would there be any performance (or other) impact to using cloned
AsyncResolver
across multiple threads at the same time. Looking through the struct, I see that there are a few other items behindArc
s, such as https://github.com/bluejekyll/trust-dns/blob/main/crates/resolver/src/name_server/name_server_pool.rs#L39-L40 which I fear might cause some kind of issues, but don't really feel like I know enough to know.If you don't think there would be any impact from that, then this PR is probably unnecessary (unless you disagree).