From e5aa2c3385270d89df857966d2d575cd94f0bd62 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 2 Dec 2023 20:20:05 +0100 Subject: mod_s2s: Close connection on smacks timeout This merges the mod_s2s_smacks_timeout behavior from prosody-modules This event is fired by mod_smacks when the connection has not responded to an ack-request for a period of time defaulting to 30 seconds, indicating that the connection has become stuck or non-responsive. Closing it prevents routing further messages via this connection and frees resources. A stuck connection may otherwise remain until for a time determined by the OS TCP subsystem, which can be quite long. --- plugins/mod_s2s.lua | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'plugins/mod_s2s.lua') diff --git a/plugins/mod_s2s.lua b/plugins/mod_s2s.lua index e7c80ddb..fcdfbca8 100644 --- a/plugins/mod_s2s.lua +++ b/plugins/mod_s2s.lua @@ -272,6 +272,12 @@ function module.add_host(module) end, 100); module:hook("s2s-authenticated", make_authenticated, -1); module:hook("s2s-read-timeout", keepalive, -1); + module:hook("smacks-ack-delayed", function (event) + if event.origin.type == "s2sin" or event.origin.type == "s2sout" then + event.origin:close("connection-timeout"); + return true; + end + end, -1); module:hook_stanza("http://etherx.jabber.org/streams", "features", function (session, stanza) -- luacheck: ignore 212/stanza local limits = stanza:get_child("limits", "urn:xmpp:stream-limits:0"); if limits then -- cgit v1.2.3