[GH-ISSUE #977] Can runtime arguments be made optional? #581

Closed
opened 2026-03-15 23:16:46 +03:00 by kerem · 6 comments
Owner

Originally created by @dfoxfranke on GitHub (Dec 29, 2019).
Original GitHub issue: https://github.com/hickory-dns/hickory-dns/issues/977

Having to pass a tokio::runtime::Handle in order to construct an AsyncResolver (or a TokioConnectionProvider) is slightly awkward because it means that programs which use AsyncResolver can't be written with a main function declared using #[tokio::main]. Programs which use #[tokio::main] never explicitly construct a tokio runtime and have no means of obtaining a handle to the one that tokio implicitly constructs. Could the runtime argument be made Optional, such that if None is passed then the resolver will just spawn tasks on the default executor using tokio::spawn()?

Originally created by @dfoxfranke on GitHub (Dec 29, 2019). Original GitHub issue: https://github.com/hickory-dns/hickory-dns/issues/977 Having to pass a `tokio::runtime::Handle` in order to construct an `AsyncResolver` (or a `TokioConnectionProvider`) is slightly awkward because it means that programs which use `AsyncResolver` can't be written with a main function declared using `#[tokio::main]`. Programs which use `#[tokio::main]` never explicitly construct a tokio runtime and have no means of obtaining a handle to the one that tokio implicitly constructs. Could the `runtime` argument be made `Option`al, such that if `None` is passed then the resolver will just spawn tasks on the default executor using `tokio::spawn()`?
kerem 2026-03-15 23:16:46 +03:00
Author
Owner

@bluejekyll commented on GitHub (Dec 29, 2019):

I'd consider it. I hate relying on thread local storage for this stuff, it makes testing really difficult. Let me review our options in this area.

It might be that we could pass in a TokioTlsHandle that carries no data, and just calls tokio::spawn. I think that would be fine. And that could be the default you're looking for.

<!-- gh-comment-id:569477839 --> @bluejekyll commented on GitHub (Dec 29, 2019): I'd consider it. I hate relying on thread local storage for this stuff, it makes testing really difficult. Let me review our options in this area. It might be that we could pass in a `TokioTlsHandle` that carries no data, and just calls `tokio::spawn`. I think that would be fine. And that could be the default you're looking for.
Author
Owner

@bluejekyll commented on GitHub (Dec 30, 2019):

Ok, I think we're going to handle this in the tokio library itself: https://github.com/tokio-rs/tokio/pull/2040

Once that or something like it lands, we can then have a default method on trust-dns-resolver then takes the thread-local instantiated Handle, which will work in this case.

<!-- gh-comment-id:569560224 --> @bluejekyll commented on GitHub (Dec 30, 2019): Ok, I think we're going to handle this in the tokio library itself: https://github.com/tokio-rs/tokio/pull/2040 Once that or something like it lands, we can then have a default method on trust-dns-resolver then takes the thread-local instantiated Handle, which will work in this case.
Author
Owner

@bluejekyll commented on GitHub (Jan 8, 2020):

FYI, with https://docs.rs/tokio/0.2.8/tokio/runtime/struct.Handle.html#method.current now in Tokio, users should be able to get a handle to the current runtime in a #[tokio::main]. I'll add a function for initializing trust-dns-resolver so that the extra code isn't necessary.

<!-- gh-comment-id:571830477 --> @bluejekyll commented on GitHub (Jan 8, 2020): FYI, with https://docs.rs/tokio/0.2.8/tokio/runtime/struct.Handle.html#method.current now in Tokio, users should be able to get a handle to the current runtime in a `#[tokio::main]`. I'll add a function for initializing trust-dns-resolver so that the extra code isn't necessary.
Author
Owner

@gzbakku commented on GitHub (Oct 25, 2020):

has this problem been resolved
how to do this??

<!-- gh-comment-id:716228172 --> @gzbakku commented on GitHub (Oct 25, 2020): has this problem been resolved how to do this??
Author
Owner

@djc commented on GitHub (Oct 26, 2020):

I think this has been solved? At least you can in 0.19 instantiate a TokioAsyncResolver that doesn't require you to pass in a Handle.

<!-- gh-comment-id:716399206 --> @djc commented on GitHub (Oct 26, 2020): I think this has been solved? At least you can in 0.19 instantiate a `TokioAsyncResolver` that doesn't require you to pass in a `Handle`.
Author
Owner

@dfoxfranke commented on GitHub (Oct 27, 2020):

Yes, this should be closed with the addition of the tokio_from_system_conf() constructor.

<!-- gh-comment-id:716915803 --> @dfoxfranke commented on GitHub (Oct 27, 2020): Yes, this should be closed with the addition of the `tokio_from_system_conf()` constructor.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/hickory-dns#581
No description provided.