internal/dns: prevent upstreams from being lost during reordering (#63)
If upstreams were reordered between start of an upstream request and its conclusion, the move-to-front operation would likely incorrectly reorder upstreams: duplicate one and remove another. Instead, we abandon the move-to-front operation if that was about to happen.
This commit is contained in:
parent
0507d93b3d
commit
8de4eb7ba1
@ -428,7 +428,10 @@ func (s *Server) handleRequest(w dns.ResponseWriter, r *dns.Msg) {
|
||||
if idx > 0 {
|
||||
// re-order this upstream to the front of s.upstream.
|
||||
s.upstreamMu.Lock()
|
||||
s.upstream = append(append([]string{u}, s.upstream[:idx]...), s.upstream[idx+1:]...)
|
||||
// if the upstreams were reordered in the meantime leave them alone
|
||||
if s.upstream[idx] == u {
|
||||
s.upstream = append(append([]string{u}, s.upstream[:idx]...), s.upstream[idx+1:]...)
|
||||
}
|
||||
s.upstreamMu.Unlock()
|
||||
}
|
||||
return
|
||||
|
Loading…
x
Reference in New Issue
Block a user