-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
feat(ext/fetch): allow embedders to use hickory_dns_resolver
instead of default GaiResolver
#26740
feat(ext/fetch): allow embedders to use hickory_dns_resolver
instead of default GaiResolver
#26740
Conversation
f5e7f20
to
377ed02
Compare
Can you please provide some information what prompted you to open this PR? It is expected that there will be several Tokio threads spawned - Deno puts a limit of "blocking" threads at 32 (or 64 on Windows) that can be used for async FS operations and others, so these won't grow unbounded. I'm skeptical of switching out the resolver as it might lead to a subtle bugs that will be hard to debug, we might want to consider having an env var, or a flag that switches the resolver though. |
@bartlomieju If you are worried about the subtle bugs (which I do agree may happen, especially because it's DNS), how about I add something like |
377ed02
to
e672d0a
Compare
Thanks for explanation, feels like something that was already tried in #22293 and #17166. I'm fine in making the resolver configurable for embedders, but for now I'd like to keep using the default resolver in Deno itself. If you could restructure the code to make resolver configurable in |
e672d0a
to
d806f7a
Compare
@bartlomieju I've applied your suggestion and made trust resolver optional. Would you please take a look? |
@sahandevs I'm off for a few days, I'll review and land this PR next week! |
c0cf2b1
to
e5e2687
Compare
runtime/examples/extension/main.rs
Outdated
@@ -50,6 +50,7 @@ async fn main() -> Result<(), AnyError> { | |||
node_services: Default::default(), | |||
npm_process_state_provider: Default::default(), | |||
root_cert_store_provider: Default::default(), | |||
fetch_resolver: Default::default(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please rename this to fetch_dns_resolver
?
ext/kv/remote.rs
Outdated
@@ -197,6 +197,7 @@ impl<P: RemoteDbHandlerPermissions + 'static> DatabaseHandler | |||
root_cert_store: options.root_cert_store()?, | |||
ca_certs: vec![], | |||
proxy: options.proxy.clone(), | |||
resolver: Default::default(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And this one to dns_resolver
ext/fetch/dns.rs
Outdated
if join_err.is_cancelled() { | ||
Err(io::Error::new(io::ErrorKind::Interrupted, join_err)) | ||
} else { | ||
panic!("gai background task failed: {:?}", join_err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be handled gracefully with an error and not a panic
e5e2687
to
3733b68
Compare
3733b68
to
ffc4118
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, thanks 👍
trust_dns_resolver
instead of default GaiResolver
hickory_dns_resolver
instead of default GaiResolver
I've noticed while calling the
fetch()
function, a new thread spawns, which I don't think is necessary. We can reproduce this easily, by running the following script and watching new threads spawn and die usinghtop
.So I investigated this issue, it seems
hyper_util::builder
uses something calledGaiResolver
in order to resolve hosts.GaiResolver
works by calling stdlib'sto_socket_addrs
in atokio::spawn_blocking
which causes tokio to spawn some worker threads.This PR fixes this issue by using
trust_dns_resolver
and replacing theGaiResolver
.