mirror of
https://github.com/hickory-dns/hickory-dns.git
synced 2026-04-25 11:15:54 +03:00
[GH-ISSUE #2456] How to use AsyncClient? #996
Labels
No labels
blocked
breaking-change
bug
bug:critical
bug:tests
cleanup
compliance
compliance
compliance
crate:all
crate:client
crate:native-tls
crate:proto
crate:recursor
crate:resolver
crate:resolver
crate:rustls
crate:server
crate:util
dependencies
docs
duplicate
easy
easy
enhance
enhance
enhance
feature:dns-over-https
feature:dns-over-quic
feature:dns-over-tls
feature:dnsssec
feature:global_lb
feature:mdns
feature:tsig
features:edns
has workaround
ops
perf
platform:WASM
platform:android
platform:fuchsia
platform:linux
platform:macos
platform:windows
pull-request
question
test
tools
tools
trust
unclear
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/hickory-dns#996
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @luigiminardim on GitHub (Sep 15, 2024).
Original GitHub issue: https://github.com/hickory-dns/hickory-dns/issues/2456
I'm trying to learn how to use the AsyncClient to create a DNS stub resolver server.
Here is my
cargo.tomlAnd here is my
main.rsAlthough the code compiles, the client never succeeds in running the query since it always prints the following error from line
println!("Error: {:#?}", e); // Always reach here:What am I doing wrong?
@marcus0x62 commented on GitHub (Sep 17, 2024):
You need to run the background task returned by AsyncClient::connect:
@luigiminardim commented on GitHub (Sep 18, 2024):
Thanks, @marcus0x62! Your solution worked for me.
Although it is functioning, I think the API it's a little bit difficult to understand. I would like to get some thoughts on this topic.
@djc commented on GitHub (Sep 18, 2024):
connect()returns a tuple and you decided in your code to ignore the second element. The documentation says:What would you suggest doing instead? This is a decently common pattern in async Rust.
We could spawn internally instead, and require the caller to pass in a
Spawner?@marcus0x62 commented on GitHub (Sep 18, 2024):
@luigiminardim what part was hard to understand? Was the documentation unclear? We do have simpler interfaces, but those tend to be for simpler use cases like basic clients and wouldn't be appropriate for building a stub resolver server.
@luigiminardim commented on GitHub (Sep 19, 2024):
@djc, Thanks for clarifying the documentation. Since I'm new to Rust, I don't know the common practices of the language. But I do think that requiring the caller to pass in a Spawner is a good idea since the user would know at compile time that he is committing a mistake. Of course, if it is possible, in my opinion, the best option is if this task management is more transparent to the user.
Also answering @marcus0x62, I think that the thing that is missing in the documentation is an example. Even in the source code test, I didn't find AsyncClient usage with a UDP connection.