From 000e842f7b86d145b3032ec18beda87d6b273272 Mon Sep 17 00:00:00 2001 From: Simon Zolin Date: Thu, 12 Dec 2019 15:00:10 +0300 Subject: [PATCH] - DNS: fix deadlock in Server.ServeHTTP() s.RLock() is called again in filterResponse() while another thread holds s.Lock() --- dnsforward/dnsforward.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/dnsforward/dnsforward.go b/dnsforward/dnsforward.go index 2988133d..f5963058 100644 --- a/dnsforward/dnsforward.go +++ b/dnsforward/dnsforward.go @@ -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) {