Skip to content

Commit

Permalink
fix: DNS upstream connection close
Browse files Browse the repository at this point in the history
  • Loading branch information
wweir committed May 19, 2022
1 parent 3412643 commit 795bf73
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions router/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,22 @@ func (r *Router) ServeDNS(w dns.ResponseWriter, req *dns.Msg) {
if err != nil {
resp, rtt, err = r.dns.ExchangeWithConn(req, conn)
}
select {
case r.dns.connCh <- conn:
default:
conn.Close()
}

log.DebugWarn(err).
Dur("rtt", rtt).
Str("question", req.Question[0].String()).
Msg("exchange dns record")
if err != nil {
_ = w.WriteMsg(r.dnsFail(req, dns.RcodeServerFailure))
conn.Close()

} else {
_ = w.WriteMsg(resp)
select {
case r.dns.connCh <- conn:
default:
conn.Close()
}
}
}

Expand Down

0 comments on commit 795bf73

Please sign in to comment.