Skip to content

Commit

Permalink
Merge pull request #100 from mailgun/neill/dev
Browse files Browse the repository at this point in the history
Adding Resolver Passing
  • Loading branch information
rneillj authored Mar 3, 2022
2 parents 0ecf5e7 + 52f5b91 commit d4b6196
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions mxresolv/mxresolv.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ var (

// It is modified only in tests to make them deterministic.
shuffle = true

DefaultResolver = net.DefaultResolver
)

func init() {
Expand All @@ -48,15 +50,15 @@ func Lookup(ctx context.Context, hostname string) ([]string, bool, error) {
if err != nil {
return nil, false, errors.Wrap(err, "invalid hostname")
}
mxRecords, err := net.DefaultResolver.LookupMX(ctx, asciiHostname)
mxRecords, err := DefaultResolver.LookupMX(ctx, asciiHostname)
if err != nil {
var timeouter interface{ Timeout() bool }
if errors.As(err, &timeouter) && timeouter.Timeout() {
return nil, false, errors.WithStack(err)
}
var netDNSError *net.DNSError
if errors.As(err, &netDNSError) && netDNSError.Err == "no such host" {
if _, err := net.DefaultResolver.LookupIPAddr(ctx, asciiHostname); err != nil {
if _, err := DefaultResolver.LookupIPAddr(ctx, asciiHostname); err != nil {
return cacheAndReturn(hostname, nil, false, errors.WithStack(err))
}
return cacheAndReturn(hostname, []string{asciiHostname}, true, nil)
Expand Down

0 comments on commit d4b6196

Please sign in to comment.