changeset 14021:d4a7cc295363

mod_s2s: Report outgoing connection failures to remote servers When setting up a new server, it can be easy to make mistakes with DNS, firewall or port forwarding that results in the ability to make outgoing connections, but not receive incoming, leading to a half-working setup where messages can be sent but not received. This can be difficult to diagnose. It is also difficult to inform the other end about the problem without a working channel in that direction, but when an incoming connection has been established, it can be closed with a stream error, which hopefully shows up in logs.
author Kim Alvefur <zash@zash.se>
date Tue, 30 Dec 2025 17:45:58 +0100
parents 3c2bfa6a69df
children 06b7a211702b
files plugins/mod_s2s.lua
diffstat 1 files changed, 11 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/mod_s2s.lua	Tue Dec 30 16:30:43 2025 +0000
+++ b/plugins/mod_s2s.lua	Tue Dec 30 17:45:58 2025 +0100
@@ -1080,6 +1080,17 @@
 
 module:hook("s2s-check-certificate", check_auth_policy, -1);
 
+-- When an outgoing connection fails, close a corresponding incoming connection with a stream error to indicate the problem to the remote
+module:hook("s2s-destroyed", function(event)
+	local s2sout = event.session;
+	if s2sout.type ~= "s2sout_unauthed" then return end
+	for s2sin in pairs(prosody.incoming_s2s) do
+		if s2sin.from_host == s2sout.to_host and s2sin.to_host == s2sout.from_host then
+			s2sin:close(errors.new({ condition = "reset", text = "Could not deliver return stanzas, please check your DNS and firewall" }));
+		end
+	end
+end);
+
 module:hook("server-stopping", function(event)
 	-- Close ports
 	local pm = require "prosody.core.portmanager";