-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
proposal: net: add QueryType to *DNSError #65288
Comments
After a quick look at the code, a simple and ugly fix looks like this. --- a/src/net/lookup.go
+++ b/src/net/lookup.go
@@ -856,6 +856,11 @@ func (r *Resolver) goLookupNS(ctx context.Context, name string) ([]*NS, error) {
func (r *Resolver) goLookupTXT(ctx context.Context, name string) ([]string, error) {
p, server, err := r.lookup(ctx, name, dnsmessage.TypeTXT, nil)
if err != nil {
+ if e, ok := err.(*DNSError); ok {
+ if e.Err == errNoSuchHost.Error() {
+ e.Err = "no TXT record"
+ }
+ }
return nil, err
}
var txts []string |
That wouldn't work. Please replace the hostname in my example with one that doesn't exist, e.g. put an "x" in front of the name. Your "fix" would say that there is no such TXT record. While it technically is true, it's not consisternt with the host command: $ host -t TXT xmail10476.emails3.rightmove.co.uk
Host xmail10476.emails3.rightmove.co.uk not found: 3(NXDOMAIN)
$ host -t TXT mail10476.emails3.rightmove.co.uk
mail10476.emails3.rightmove.co.uk has no TXT record Is there any way to get the underlying DNS errors? |
We currently return "no such host" for NXDOMAIN and NODATA conditions. Maybe we should change that and return "no such host" (or "no such domain") and "no records found"? |
I think, this is a good idea. In my current project I'm using Perl for the lookups I have to do. But I want to switch to go. Unfortunately I currently report the DNS errors to my customers and with the
This would be perfect. |
Ok, lets make this a proposal then. I propose adding a package net
type DNSError struct {
// (...)
QueryType string
}
func (e *DNSError) Error() string {
if e == nil {
return "<nil>"
}
s := "lookup: "
if e.QueryType != "" {
s += e.QueryType + ": "
}
s += e.Name
if e.Server != "" {
s += " on " + e.Server
}
s += ": " + e.Err
return s
} The only question remains how to handle The |
I would first make sure what @Skeeve's original wish regarding the stated problem was. I have one more concern (maybe misguided): I would not say that having zero TXT records for an existing domain is an error to begin with. In the OP's case I would expect |
I don't think that this kind of change is backwards compatible at this point. |
First of all I thought that "no such host" for a missing TXT record is plain wrong. That's where I came from. So regarding your other statement:
I fully agree. A missing TXT record is not an error. An empty slice or a nil for the slice would perfectly indicate the "missingness" of the record
That would be a nice-to have. So being able to drill down without going to another module which allows "bare-bones" DNS access would be very helpful, at least to me.
That's for sure. Maybe providing another function for that purpose would help here? |
This can be implemented, but i would block this on #63116, so that we don't pollute the DNSError with more fields (we already have IsNotFound). Then we can define a global errors: var (
ErrNoSuchDomain = errors.New("no such domain") // DNS NXDOMAIN
ErrNoRecordsFound = errors.New("no records found") // DNS NODATA
) But then question remains on how to handle Personally I think that if you need this kind of access you should use a DNS library directly like miekg/dns. |
Oh, that is super cool: I, for one, was puzzled when I've discovered it's impossible to somehow "fetch" a non-string reason from a
While I would prefer a
I would treat a missing Also–again, may be my guess is misguided,–but I thought it's only posisble to have equivalents of A and AAAA (and PTR) records in |
I'd go with what Or did I misunderstand?
I thought about switching to it. It's just a question of: Is it worth it? After all: I think, and I might be wrong here, the information is already available when using P.S. "Is it worth it?" My concern here is: What's the effort switching? What's the effort learning it? I'm not a DNS "expert" and to me it looked complicated. On the other hand |
I don't agree that /etc/hosts should return a LookupHost("not-in-hosts.example.com") // might return NXDOMAIN when nsswitch.conf is `dns: files`
LookupTXT("not-in-hosts.example.com") // returns an answer even though LookupHost returned NXDOMAIN. |
For sure I'm not too deeply involved in this, so what exactly do you mean with |
NXDOMAIN response means that the requested domain does not contain any records, but depending on the system configuration that might not hold true, like in the example: LookupHost("not-in-hosts.example.com") // might return NXDOMAIN when nsswitch.conf is `hosts: files`
LookupTXT("not-in-hosts.example.com") // returns an answer even though LookupHost returned NXDOMAIN
Yes, in case where the system is configured to only use This is why I am fine with returning strings "no such domain" "no records found", but don't like the idea of separate exported errors because of cases like that. And who knows what the getaddrinfo (through nss modules) and windows report in similar cases. |
It makes no sense to me, that, if you explicitly limit yourself to one specific source, why the answer |
But then, why would you want to distinguish NXDOMAIN/NODATA errors in the first place? Maybe i am missing something, we might be looking at this from a different perspective. I've only seen it used to early abort multiple DNS queries, when the first one returns NXDOMAIN (then we are sure that next lookups would return the same response (NXDOMAIN) for the same name). |
I'm currently using a Perl script which distinguishes, so my users know these answers. Now I want to switch to go and, with this library I don't get those answers. Don't get me wrong: I do not require them. It simply would be nice to have. |
Go version
go version go1.21.6 linux/amd64
Output of
go env
in your module/workspace:What did you do?
https://go.dev/play/p/oN0gVQA4nm2
Please Note: On goplay lookups don't work. You have to run it locally.
What did you see happen?
Host Lookup
[208.73.7.224]
TXT Lookup
[]
lookup mail10476.emails3.rightmove.co.uk on 192.168.65.7:53: no such host
What did you expect to see?
Instead of "no such host" I would hav expected "no TXT record"
See also
https://stackoverflow.com/questions/77880685/golang-net-lookuptxt-returns-no-such-host
The text was updated successfully, but these errors were encountered: