net.adns: Catch errors in DNS response callbacks

Fri, 10 Apr 2009 10:30:50 +0100

author
Matthew Wild <mwild1@gmail.com>
date
Fri, 10 Apr 2009 10:30:50 +0100
changeset 973
b091a1a7273b
parent 971
dd736391bd41
child 974
82f7261c0482

net.adns: Catch errors in DNS response callbacks

net/adns.lua file | annotate | diff | comparison | revisions
--- a/net/adns.lua	Wed Apr 08 23:20:45 2009 +0100
+++ b/net/adns.lua	Fri Apr 10 10:30:50 2009 +0100
@@ -3,7 +3,7 @@
 
 local log = require "util.logger".init("adns");
 
-local coroutine, tostring = coroutine, tostring;
+local coroutine, tostring, pcall = coroutine, tostring, pcall;
 
 module "adns"
 
@@ -14,7 +14,10 @@
 				dns.query(qname, qtype, qclass);
 				coroutine.yield(nil); -- Wait for reply
 				log("debug", "Reply for "..qname.." (%s)", tostring(coroutine.running()));
-				handler(dns.peek(qname, qtype, qclass));
+				local ok, err = pcall(handler, dns.peek(qname, qtype, qclass));
+				if not ok then
+					log("debug", "Error in DNS response handler: %s", tostring(err));
+				end
 			end)();
 end
 

mercurial