s2smanager: Fix to correctly bounce stanzas if first connection attempt fails instantly

Wed, 08 Jul 2009 03:14:12 +0100

author
Matthew Wild <mwild1@gmail.com>
date
Wed, 08 Jul 2009 03:14:12 +0100
changeset 1492
aaeccebad0f3
parent 1491
694a0a00e1a5
child 1493
42a6a197bed1

s2smanager: Fix to correctly bounce stanzas if first connection attempt fails instantly

core/s2smanager.lua file | annotate | diff | comparison | revisions
--- a/core/s2smanager.lua	Wed Jul 08 02:29:13 2009 +0100
+++ b/core/s2smanager.lua	Wed Jul 08 03:14:12 2009 +0100
@@ -142,6 +142,7 @@
 			host_session.log = log;
 		end
 		
+		-- This is the first call, can't fail (the first step is DNS lookup)
 		attempt_connection(host_session);
 		
 		if not host_session.sends2s then		
@@ -195,7 +196,13 @@
 				log("debug", to_host.." has no SRV records, falling back to A");
 			end
 			-- Try with SRV, or just the plain hostname if no SRV
-			return try_connect(host_session, connect_host, connect_port);
+			local ok, err = try_connect(host_session, connect_host, connect_port);
+			if not ok then
+				if not attempt_connection(host_session, err) then
+					-- No more attempts will be made
+					destroy_session(host_session);
+				end
+			end
 		end, "_xmpp-server._tcp."..connect_host..".", "SRV");
 		
 		-- Set handler for DNS timeout
@@ -239,7 +246,7 @@
 	local success, err = conn:connect(connect_host, connect_port);
 	if not success and err ~= "timeout" then
 		log("warn", "s2s connect() to %s (%s:%d) failed: %s", host_session.to_host, connect_host, connect_port, err);
-		return false;
+		return false, err;
 	end
 	
 	local cl = connlisteners_get("xmppserver");

mercurial