net.dns: Fix duplicated cache insertions by limiting outstanding queries per name to one
authorKim Alvefur <zash@zash.se>
Mon, 30 Jun 2014 12:45:53 +0200
changeset 6288 d122420542fb
parent 6287 a380b09649e6
child 6289 a29cc79295e6
child 6297 5b298a6ecf0c
net.dns: Fix duplicated cache insertions by limiting outstanding queries per name to one
net/dns.lua
--- a/net/dns.lua	Wed Jun 25 15:33:49 2014 +0200
+++ b/net/dns.lua	Mon Jun 30 12:45:53 2014 +0200
@@ -715,6 +715,14 @@
 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 @@
 	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);