net.dns: Fix duplicated cache insertions by limiting outstanding queries per name...
authorKim Alvefur <zash@zash.se>
Mon, 30 Jun 2014 10:45:53 +0000 (12:45 +0200)
committerKim Alvefur <zash@zash.se>
Mon, 30 Jun 2014 10:45:53 +0000 (12:45 +0200)
net/dns.lua

index cdd949a22309fe2be2be70f64eee6e9ae3dc8622..492bd1c5e0dd2eb91ce57e070615de0aaeed2146 100644 (file)
@@ -715,6 +715,14 @@ end
 function resolver:query(qname, qtype, qclass)    -- - - - - - - - - - -- query
        qname, qtype, qclass = standardize(qname, qtype, qclass)
 
+       local co = coroutine.running();
+       local q = get(self.wanted, qclass, qtype, qname);
+       if co and q then
+               -- We are already waiting for a reply to an identical query.
+               set(self.wanted, qclass, qtype, qname, co, true);
+               return true;
+       end
+
        if not self.server then self:adddefaultnameservers(); end
 
        local question = encodeQuestion(qname, qtype, qclass);
@@ -735,7 +743,6 @@ function resolver:query(qname, qtype, qclass)    -- - - - - - - - - - -- query
        self.active[id][question] = o;
 
        -- remember which coroutine wants the answer
-       local co = coroutine.running();
        if co then
                set(self.wanted, qclass, qtype, qname, co, true);
                --set(self.yielded, co, qclass, qtype, qname, true);