-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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(unstable): add Deno.resolveDns API #8790
Conversation
CC @mrkurt thoughts? |
There's a widely used dns resolver crate: https://docs.rs/trust-dns-resolver/0.19.6/trust_dns_resolver/ |
I think maybe the What I'd like is the equivalent of this
That queries AAAA records on the |
@mrkurt |
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.
@magurotuna looks great! Could we get some integration tests for this feature?
@mrkurt thanks for the review, if you have any suggestions regarding missing functionality that would be helpful (it seems you'll be the first user of this API 😄 )
I added an integration test named deno/cli/tests/079_resolve_dns.ts.out Lines 2 to 9 in 4b8f870
In particular, In addition, as to the Lastly, should trailing periods in |
@magurotuna Thank you for doing this work to return strings. Now that I see this, it seems less preferable to the original version with interface for each DNS record, because of the difficult to_string implementations in SRV and PTR . I apologize for the extra work and suggesting the wrong direction. |
test_util/src/lib.rs
Outdated
@@ -678,6 +701,130 @@ async fn wrap_abs_redirect_server() { | |||
} | |||
} | |||
|
|||
async fn run_dns_server() { |
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 is very awesome, but I think it should be done in cli/tests/integration_tests.rs since it's only used in a single test.
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.
but I think it should be done in cli/tests/integration_tests.rs since it's only used in a single test.
Makes sense, but when I tried to move run_dns_server
to integration_tests.rs
, I ran into a pretty weird error, which indicated that DNS resolution was timed out.
I'm struggling to figure out why this error happened. For now, it has turned out that this snippet does work (note that it's in the main function), however, if I put exactly same stuff into a test (annotated with #[tokio::test]
), it does NOT work somehow.
(in this snippet I use dig
command instead of TypeScript code. But if I switch to TypeScript code, timeout error still happens)
I think Deno's next release is coming nearly, and it looks like this error will take me some time to solve. So I'd like to suggest putting off this refacroting after the release - if this is fine, I'll fix the return type of Deno.resolveDns
and adjust the test case to it as soon as possible.
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.
Actually I've figured out why, so I'm doing this refactoring right now.
I think it's ready to land. Please take a look :-) |
Tested this locally, and works as expected. Great work @magurotuna. I'll leave the final review to @ry. |
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.
LGTM - very nice work @magurotuna !
This PR adds new ops,
op_resolve_addr_sync
andop_resolve_addr_async
which do DNS resolution, and exposes them asDeno.resolveAddrSync
andDeno.resolveAddr
respectively.It comes from @ry's comment: #8743 (review), and also resolves #6110.
For manual testing, I prepared a script like:
then ran it via
cargo run -- run --allow-net foo.ts
, I got:Seeing this result, I wonder if we need really to pass a port number to
Deno.resolveAddr
. As far as I understand, domain name resolution itself has nothing to do with a port number, butstd::net::ToSocketAddr
andtokio::net::lookup_host
require a port number as well as hostname.If
Deno.resolveAddr
andDeno.resolveAddrSync
should be specialized in resolving domain name, it would be nice for the functions not to receive port numbers, and to return resolved addresses with port numbers truncated.