diff core/s2smanager.lua @ 13987:4067a95336dd

mod_s2s, s2smanager: Experimental s2s_block_immediate_retries option Currently, if Prosody fails to connect to a remote domain, any pending stanzas are bounced back to the sender. If the code processing these stanzas responds to the error, we will begin a new outgoing connection before we've even finished processing the last one. This generally hasn't been a problem, Prosody handles it fine. However, it is questionable whether this is sensible behaviour (if we *just* failed to connect, will an immediate retry even work most of the time?). It can also lead to some awkward traffic patterns, e.g. when combined with MUC. For example, when a MUC receives an error from a remote user, it may kick that user from the MUC. This will cause a stanza to be sent to everyone else in the MUC. If other users from the same domain are present, the notification will be sent to the remote domain, triggering a new connection attempt for no reason (the user was likely about to be kicked anyway after the sendq had finished being bounced). This new option enables an alternative strategy, where attempts to send to the remote domain that failed will be rejected until the sendq has finished being processed. To enable the new behaviour, set the global option: s2s_block_immediate_retries = true
author Matthew Wild <mwild1@gmail.com>
date Thu, 16 Oct 2025 18:29:03 +0100
parents ead41e25ebc0
children
line wrap: on
line diff
--- a/core/s2smanager.lua	Wed Oct 15 02:12:51 2025 +0200
+++ b/core/s2smanager.lua	Thu Oct 16 18:29:03 2025 +0100
@@ -91,8 +91,17 @@
 	log("debug", "Destroying %s session %s->%s%s%s", session.direction, session.from_host, session.to_host, reason and ": " or "", reason or "");
 
 	if session.direction == "outgoing" then
-		hosts[session.from_host].s2sout[session.to_host] = nil;
-		session:bounce_sendq(bounce_reason or reason);
+		if session.block_retries then
+			-- Reject any attempts to communicate with the failed domain
+			-- while we are bouncing the stanzas
+			session.send = function () return false; end
+			session.sends2s = function () return false; end
+			session:bounce_sendq(bounce_reason or reason);
+			hosts[session.from_host].s2sout[session.to_host] = nil;
+		else
+			hosts[session.from_host].s2sout[session.to_host] = nil;
+			session:bounce_sendq(bounce_reason or reason);
+		end
 	elseif session.direction == "incoming" then
 		if session.outgoing and hosts[session.to_host].s2sout[session.from_host] == session then
 			hosts[session.to_host].s2sout[session.from_host] = nil;