comparison plugins/mod_c2s.lua @ 14155:ead9e645741a 0.12

mod_c2s: Remove timers immediately on disconnection
author Waqas Hussain <waqas20@gmail.com>
date Thu, 16 Apr 2026 18:59:56 +0100
parents 363a79f54109
children e3ddbf7f2d3f
comparison
equal deleted inserted replaced
14154:363a79f54109 14155:ead9e645741a
6 -- COPYING file in the source package for more information. 6 -- COPYING file in the source package for more information.
7 -- 7 --
8 8
9 module:set_global(); 9 module:set_global();
10 10
11 local add_task = require "util.timer".add_task; 11 local timer = require "util.timer";
12 local add_task = timer.add_task;
13 local stop_task = timer.stop;
12 local new_xmpp_stream = require "util.xmppstream".new; 14 local new_xmpp_stream = require "util.xmppstream".new;
13 local nameprep = require "util.encodings".stringprep.nameprep; 15 local nameprep = require "util.encodings".stringprep.nameprep;
14 local sessionmanager = require "core.sessionmanager"; 16 local sessionmanager = require "core.sessionmanager";
15 local statsmanager = require "core.statsmanager"; 17 local statsmanager = require "core.statsmanager";
16 local st = require "util.stanza"; 18 local st = require "util.stanza";
25 27
26 local log = module._log; 28 local log = module._log;
27 29
28 local c2s_timeout = module:get_option_number("c2s_timeout", 300); 30 local c2s_timeout = module:get_option_number("c2s_timeout", 300);
29 local stream_close_timeout = module:get_option_number("c2s_close_timeout", 5); 31 local stream_close_timeout = module:get_option_number("c2s_close_timeout", 5);
32
33 local function stop_session_timers(session)
34 if session.c2s_timeout then
35 stop_task(session.c2s_timeout);
36 session.c2s_timeout = nil;
37 end
38 end
39
30 local opt_keepalives = module:get_option_boolean("c2s_tcp_keepalives", module:get_option_boolean("tcp_keepalives", true)); 40 local opt_keepalives = module:get_option_boolean("c2s_tcp_keepalives", module:get_option_boolean("tcp_keepalives", true));
31 local unauthed_stanza_size_limit = module:get_option_number("c2s_unauthed_stanza_size_limit", 10000,1000); 41 local unauthed_stanza_size_limit = module:get_option_number("c2s_unauthed_stanza_size_limit", 10000,1000);
32 local authed_stanza_size_limit = module:get_option_number("c2s_stanza_size_limit", 1024*256,10000); 42 local authed_stanza_size_limit = module:get_option_number("c2s_stanza_size_limit", 1024*256,10000);
33 local max_child_elements = module:get_option_number("c2s_max_child_elements", 25000, 0); 43 local max_child_elements = module:get_option_number("c2s_max_child_elements", 25000, 0);
34 44
190 local function session_close(session, reason) 200 local function session_close(session, reason)
191 local log = session.log or log; 201 local log = session.log or log;
192 local close_event_payload = { session = session, reason = reason }; 202 local close_event_payload = { session = session, reason = reason };
193 module:context(session.host):fire_event("pre-session-close", close_event_payload); 203 module:context(session.host):fire_event("pre-session-close", close_event_payload);
194 reason = close_event_payload.reason; 204 reason = close_event_payload.reason;
205 stop_session_timers(session);
195 if session.conn then 206 if session.conn then
196 if session.notopen then 207 if session.notopen then
197 session:open_stream(); 208 session:open_stream();
198 end 209 end
199 if reason then -- nil == no err, initiated by us, false == initiated by client 210 if reason then -- nil == no err, initiated by us, false == initiated by client
383 394
384 function listener.ondisconnect(conn, err) 395 function listener.ondisconnect(conn, err)
385 local session = sessions[conn]; 396 local session = sessions[conn];
386 if session then 397 if session then
387 (session.log or log)("info", "Client disconnected: %s", err or "connection closed"); 398 (session.log or log)("info", "Client disconnected: %s", err or "connection closed");
399 stop_session_timers(session);
388 sm_destroy_session(session, err); 400 sm_destroy_session(session, err);
389 session.conn = nil; 401 session.conn = nil;
390 sessions[conn] = nil; 402 sessions[conn] = nil;
391 end 403 end
392 module:fire_event("c2s-closed", { session = session; conn = conn }); 404 module:fire_event("c2s-closed", { session = session; conn = conn });