Skip to content
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

DNS : Fixes recursors answering the DNS query to properly return the correct response. #4461

Merged
merged 4 commits into from
Aug 2, 2018

Conversation

MagnumOpus21
Copy link
Contributor

This PR addresses the fact that if multiple recursors are provided to the Consul agent, Consul tries to fetch the DNS query instead of prematurely returning the response received from the first known recursor. i.e If a recursor returns a response like SERVFAIL or REFUSED the previous behaviour was to return the DNS response, instead of moving onto the next recursor for getting the DNS query issued.
Fixes #4426

Copy link
Member

@mkeeler mkeeler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of the comments are inline.

One additional request is that you add a tests for the all recursors failing and returning SERVFAIL ourselves.

agent/dns.go Outdated
// Check if the response is valid and has the desired Response code
if r != nil && (r.Rcode != dns.RcodeSuccess && r.Rcode != dns.RcodeNameError) {
d.logger.Printf("[DEBUG] dns: recurse RTT for %v (%v) Recursor queried: %v Status returned: %v", q, rtt, recursor, dns.RcodeToString[r.Rcode])
// This is so that if the last known recursor also throws an error
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont think the body inside the if {} here is doing anything useful other than logging the recursor failure.

Condensed down this is the logic you have.

for ... {
   if ... {
      if last recursor {
         break
      }
      continue
   } else {
      if no error or truncated {
         write out the response
         return
      }
   }
}

The break if its the last recursor and continuing the loop will do the exact same thing which is to finish/exit the loop. This could be condensed into

for ... {
   if bad rcode {
      log
      continue
   }

   if no error or truncated {
      write out response
      return
   }
}

Copy link
Contributor Author

@MagnumOpus21 MagnumOpus21 Jul 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted. I felt that the other it was totally unnecessary. Still wanted to get an opinion. Will add the test case and push it.

@MagnumOpus21
Copy link
Contributor Author

MagnumOpus21 commented Jul 27, 2018

Added in the requested changes. I left the main if{} else block control structure untouched, because I didn't want to do the same check twice. Other than that I hope, I've addressed the points raised here. 😄

Copy link
Member

@mkeeler mkeeler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just the one thing.

agent/dns.go Outdated
// we move forward onto the next one else the loop ends
continue
} else {
if err == nil || err == dns.ErrTruncated {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving the same conditions and body is fine but this really should be

} else if err == nil || err == dns.ErrTruncated {
<body>
}

There is no reason to have the extra indentation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha

Copy link
Member

@mkeeler mkeeler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@MagnumOpus21 MagnumOpus21 merged commit 865068a into hashicorp:master Aug 2, 2018
@MagnumOpus21 MagnumOpus21 deleted the fix-DNS branch August 2, 2018 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants