Changeset

8267:42fad8465537

mod_s2s: Use a separate resolver object for each outgoing session Cleaner approach hopefully fixes problems with some peoples' DNS hanging after a while, failed DNS when a large number of queries are made at once, and source port re-use. Related issues: #487, 761, #991, #992, #1001
author Matthew Wild <mwild1@gmail.com>
date Mon, 25 Sep 2017 23:12:47 +0100
parents 8266:9a97dd174ec9
children 8268:e21d82551e05 8269:25237002aba4
files plugins/mod_s2s/mod_s2s.lua plugins/mod_s2s/s2sout.lib.lua
diffstat 2 files changed, 7 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/mod_s2s/mod_s2s.lua	Mon Sep 25 23:06:00 2017 +0100
+++ b/plugins/mod_s2s/mod_s2s.lua	Mon Sep 25 23:12:47 2017 +0100
@@ -174,6 +174,7 @@
 
 -- Stream is authorised, and ready for normal stanzas
 function mark_connected(session)
+
 	local sendq = session.sendq;
 
 	local from, to = session.from_host, session.to_host;
@@ -205,6 +206,7 @@
 			session.sendq = nil;
 		end
 
+		session.resolver = nil;
 		session.ip_hosts = nil;
 		session.srv_hosts = nil;
 	end
--- a/plugins/mod_s2s/s2sout.lib.lua	Mon Sep 25 23:06:00 2017 +0100
+++ b/plugins/mod_s2s/s2sout.lib.lua	Mon Sep 25 23:12:47 2017 +0100
@@ -49,6 +49,8 @@
 	initialize_filters(host_session);
 	host_session.version = 1;
 
+	host_session.resolver = adns.resolver();
+
 	-- Kick the connection attempting machine into life
 	if not s2sout.attempt_connection(host_session) then
 		-- Intentionally not returning here, the
@@ -84,9 +86,7 @@
 	if not err then -- This is our first attempt
 		log("debug", "First attempt to connect to %s, starting with SRV lookup...", to_host);
 		host_session.connecting = true;
-		local handle;
-		handle = adns.lookup(function (answer)
-			handle = nil;
+		host_session.resolver:lookup(function (answer)
 			local srv_hosts = { answer = answer };
 			host_session.srv_hosts = srv_hosts;
 			host_session.srv_choice = 0;
@@ -168,7 +168,7 @@
 		local have_other_result = not(has_ipv4) or not(has_ipv6) or false;
 
 		if has_ipv4 then
-			handle4 = adns.lookup(function (reply, err)
+			handle4 = host_session.resolver:lookup(function (reply, err)
 				handle4 = nil;
 
 				if reply and reply[#reply] and reply[#reply].a then
@@ -206,7 +206,7 @@
 		end
 
 		if has_ipv6 then
-			handle6 = adns.lookup(function (reply, err)
+			handle6 = host_session.resolver:lookup(function (reply, err)
 				handle6 = nil;
 
 				if reply and reply[#reply] and reply[#reply].aaaa then