Mercurial > prosody-hg
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 14144:e38916e22f59 | 14146:1d028f9473c2 |
|---|---|
| 73 local max_unacked_stanzas = module:get_option_integer("smacks_max_unacked_stanzas", 0, 0); | 73 local max_unacked_stanzas = module:get_option_integer("smacks_max_unacked_stanzas", 0, 0); |
| 74 local max_inactive_unacked_stanzas = module:get_option_integer("smacks_max_inactive_unacked_stanzas", 256, 0); | 74 local max_inactive_unacked_stanzas = module:get_option_integer("smacks_max_inactive_unacked_stanzas", 256, 0); |
| 75 local delayed_ack_timeout = module:get_option_period("smacks_max_ack_delay", 30); | 75 local delayed_ack_timeout = module:get_option_period("smacks_max_ack_delay", 30); |
| 76 local max_old_sessions = module:get_option_integer("smacks_max_old_sessions", 10, 0); | 76 local max_old_sessions = module:get_option_integer("smacks_max_old_sessions", 10, 0); |
| 77 | 77 |
| 78 local c2s_sessions = module:shared("/*/c2s/sessions"); | |
| 79 local local_sessions = prosody.hosts[module.host].sessions; | 78 local local_sessions = prosody.hosts[module.host].sessions; |
| 80 | 79 |
| 81 local function format_h(h) if h then return string.format("%d", h) end end | 80 local function format_h(h) if h then return string.format("%d", h) end end |
| 82 | 81 |
| 83 local all_old_sessions = module:open_store("smacks_h"); | 82 local all_old_sessions = module:open_store("smacks_h"); |
| 552 sessions_expired(1); | 551 sessions_expired(1); |
| 553 end; | 552 end; |
| 554 }); | 553 }); |
| 555 end); | 554 end); |
| 556 if session.conn then | 555 if session.conn then |
| 557 local conn = session.conn; | 556 session.conn:close(); |
| 558 c2s_sessions[conn] = nil; | |
| 559 session.conn = nil; | |
| 560 conn:close(); | |
| 561 end | 557 end |
| 562 session.log("debug", "Session going into hibernation (not being destroyed)") | 558 session.log("debug", "Session going into hibernation (not being destroyed)") |
| 563 module:fire_event("smacks-hibernation-start", { origin = session; queue = session.outgoing_stanza_queue:table() }); | 559 module:fire_event("smacks-hibernation-start", { origin = session; queue = session.outgoing_stanza_queue:table() }); |
| 564 return true; -- Postpone destruction for now | 560 return true; -- Postpone destruction for now |
| 565 end); | 561 end); |
