mirror of
https://github.com/hickory-dns/hickory-dns.git
synced 2026-04-25 03:05:51 +03:00
[GH-ISSUE #713] How to use SyncClient with tokio_threadpool? #278
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#278
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 @jgillich on GitHub (Mar 24, 2019).
Original GitHub issue: https://github.com/hickory-dns/hickory-dns/issues/713
I'm getting this error when I try to use SyncClient:
This is in a synchronous context (Juniper resolver) within
tokio_threadpool::blocking.@bluejekyll commented on GitHub (Mar 24, 2019):
Ah, SyncClient uses Tokio internally. This error is an artifact of the thread-local-executor usage in Tokio. The short answer is that you'll need to switch to use the ClientFuture (inconsistent naming I know), and switch over to use the futures for the client.
As an aside, the trust-dns-resolver is a full stub resolver, i'm not sure what the Juniper resolver is.
@jgillich commented on GitHub (Mar 24, 2019):
Sorry, I should have mentioned that I was referring to Juniper the GraphQL library. It's fully synchronous but wrapped by Warp (the web framework), which is async. I've already tried ClientFuture, but tokio is a bit confusing. Everything I can find seems to indicate that I need to spawn a new thread, do you know if that's correct or if there's another way?
@bluejekyll commented on GitHub (Mar 24, 2019):
Yes, the
ClientFutureis confusing, there are examples of it's usage, though: https://docs.rs/trust-dns/0.16.0-alpha.2/trust_dns/#async-usage. TheClientFuturewould not require a separate thread, butSyncClientwould.I'd like to simplify the Client if possible. It's been a little while since I've looked at trying to do that.
@jgillich commented on GitHub (Mar 24, 2019):
I tried that but it's also panicking with the message from above.
@bluejekyll commented on GitHub (Mar 24, 2019):
Do you have a link to code? If I find some time, I could take a look and see what's going on?
@jgillich commented on GitHub (Mar 24, 2019):
Sure, here's an example: https://github.com/jgillich/clientfuture
To trigger the field, do
The synch wrapper is in juniper_warp: https://github.com/graphql-rust/juniper/blob/master/juniper_warp/src/lib.rs#L181
@bluejekyll commented on GitHub (Mar 24, 2019):
Ok, so your code is spawning a new Runtime for tokio. Since this is already running, you don't want a new one. What you want is to get a handle to the Executor that's already registered. I think you might want to look at https://docs.rs/tokio-executor/0.1.7/tokio_executor/struct.DefaultExecutor.html which has a current, and would allow you to get at the currently registered executor.
@jgillich commented on GitHub (Mar 24, 2019):
Woo yes, that's it, thank you!
For future reference, this works: