- DNS: fix deadlock in Server.ServeHTTP()

s.RLock() is called again in filterResponse() while another thread
 holds s.Lock()
This commit is contained in:
Simon Zolin 2019-12-12 15:00:10 +03:00
parent c9ccc53282
commit 000e842f7b
1 changed files with 4 additions and 1 deletions

View File

@ -380,8 +380,11 @@ func (s *Server) Reconfigure(config *ServerConfig) error {
// ServeHTTP is a HTTP handler method we use to provide DNS-over-HTTPS
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
s.RLock()
s.dnsProxy.ServeHTTP(w, r)
p := s.dnsProxy
s.RUnlock()
if p != nil { // an attempt to protect against race in case we're here after Close() was called
p.ServeHTTP(w, r)
}
}
func (s *Server) beforeRequestHandler(p *proxy.Proxy, d *proxy.DNSContext) (bool, error) {