فهرست منبع

Merge pull request #1088 from sanimej/udp

Fix the panic when a query response comes after the read() timesout
Madhu Venugopal 9 سال پیش
والد
کامیت
dfdee91fb3
1فایلهای تغییر یافته به همراه4 افزوده شده و 5 حذف شده
  1. 4 5
      libnetwork/resolver.go

+ 4 - 5
libnetwork/resolver.go

@@ -45,7 +45,7 @@ const (
 	ptrIPv6domain   = ".ip6.arpa."
 	ptrIPv6domain   = ".ip6.arpa."
 	respTTL         = 600
 	respTTL         = 600
 	maxExtDNS       = 3 //max number of external servers to try
 	maxExtDNS       = 3 //max number of external servers to try
-	extIOTimeout    = 3 * time.Second
+	extIOTimeout    = 4 * time.Second
 	defaultRespSize = 512
 	defaultRespSize = 512
 	maxConcurrent   = 50
 	maxConcurrent   = 50
 	logInterval     = 2 * time.Second
 	logInterval     = 2 * time.Second
@@ -344,9 +344,6 @@ func (r *resolver) ServeDNS(w dns.ResponseWriter, query *dns.Msg) {
 			if extDNS.ipStr == "" {
 			if extDNS.ipStr == "" {
 				break
 				break
 			}
 			}
-			log.Debugf("Query %s[%d] from %s, forwarding to %s:%s", name, query.Question[0].Qtype,
-				w.LocalAddr().String(), proto, extDNS.ipStr)
-
 			extConnect := func() {
 			extConnect := func() {
 				addr := fmt.Sprintf("%s:%d", extDNS.ipStr, 53)
 				addr := fmt.Sprintf("%s:%d", extDNS.ipStr, 53)
 				extConn, err = net.DialTimeout(proto, addr, extIOTimeout)
 				extConn, err = net.DialTimeout(proto, addr, extIOTimeout)
@@ -378,6 +375,8 @@ func (r *resolver) ServeDNS(w dns.ResponseWriter, query *dns.Msg) {
 			if extConn == nil {
 			if extConn == nil {
 				continue
 				continue
 			}
 			}
+			log.Debugf("Query %s[%d] from %s, forwarding to %s:%s", name, query.Question[0].Qtype,
+				extConn.LocalAddr().String(), proto, extDNS.ipStr)
 
 
 			// Timeout has to be set for every IO operation.
 			// Timeout has to be set for every IO operation.
 			extConn.SetDeadline(time.Now().Add(extIOTimeout))
 			extConn.SetDeadline(time.Now().Add(extIOTimeout))
@@ -424,7 +423,7 @@ func (r *resolver) ServeDNS(w dns.ResponseWriter, query *dns.Msg) {
 			break
 			break
 		}
 		}
 
 
-		if resp == nil {
+		if resp == nil || w == nil {
 			return
 			return
 		}
 		}
 	}
 	}