changeset 14144:e38916e22f59 13.0

mod_limits: Only count connections with associated sessions I suspect some (all??) network backends and some edge cases cause ondisconnect to be called more than once. mod_c2s and mod_s2s already handle this, skipping cleanup if there is no session associated. Sessions are assigned very early on in onconnect, so it seems like a reliable way of counting.
author Matthew Wild <mwild1@gmail.com>
date Fri, 17 Apr 2026 19:42:44 +0100
parents 723c6f5f01b7
children b6b09dace24b 1d028f9473c2
files plugins/mod_limits.lua
diffstat 1 files changed, 2 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/mod_limits.lua	Fri Apr 17 19:40:56 2026 +0100
+++ b/plugins/mod_limits.lua	Fri Apr 17 19:42:44 2026 +0100
@@ -67,6 +67,7 @@
 	-- [packed_truncated_ip] = count
 	local current_ips = module:shared("ips."..session_type);
 	module:hook(session_type.."-connected", function (event)
+		if not event.session then return; end
 		local session_ip = get_truncated_ip(event.conn);
 		local new_count = (current_ips[session_ip] or 0) + 1;
 		current_ips[session_ip] = new_count;
@@ -77,6 +78,7 @@
 	end);
 
 	module:hook(session_type.."-closed", function (event)
+		if not event.session then return; end
 		local session_ip = get_truncated_ip(event.conn);
 		local new_count = (current_ips[session_ip] or 0) - 1;
 		if new_count < 0 then