diff plugins/mod_smacks.lua @ 14146:1d028f9473c2 13.0

mod_c2s, mod_smacks: Refactor session/connection cleanup mod_smacks was preventing mod_c2s cleanup by directly modifying the mod_c2s sessions table. It did this to avoid mod_c2s trying to destroy the session when the connection was closed. The code that does IP counting in mod_limits was experiencing counter drift, likely because of mod_smacks disassociating the session from the connection before the c2s-closed event is fired. This change has mod_c2s skip the session cleanup if it sees the 'hibernating' property is set on the session. This is a less invasive way of performing the same thing. Importantly, c2s-closed still gets to run and fire with the original session object. It might be desirable to remove the 'hibernating' check here and switch to a more generic event-driven design (where mod_smacks can inhibit cleanup by adding an event handler). This change was deemed too large for a minor release, but may be made in trunk.
author Matthew Wild <mwild1@gmail.com>
date Tue, 21 Apr 2026 16:22:43 +0100
parents 5f8a9e50c2fb
children
line wrap: on
line diff
--- a/plugins/mod_smacks.lua	Fri Apr 17 19:42:44 2026 +0100
+++ b/plugins/mod_smacks.lua	Tue Apr 21 16:22:43 2026 +0100
@@ -75,7 +75,6 @@
 local delayed_ack_timeout = module:get_option_period("smacks_max_ack_delay", 30);
 local max_old_sessions = module:get_option_integer("smacks_max_old_sessions", 10, 0);
 
-local c2s_sessions = module:shared("/*/c2s/sessions");
 local local_sessions = prosody.hosts[module.host].sessions;
 
 local function format_h(h) if h then return string.format("%d", h) end end
@@ -554,10 +553,7 @@
 		});
 	end);
 	if session.conn then
-		local conn = session.conn;
-		c2s_sessions[conn] = nil;
-		session.conn = nil;
-		conn:close();
+		session.conn:close();
 	end
 	session.log("debug", "Session going into hibernation (not being destroyed)")
 	module:fire_event("smacks-hibernation-start", { origin = session; queue = session.outgoing_stanza_queue:table() });