Mercurial > prosody-hg
comparison plugins/mod_c2s.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 | 836a70deb3c9 |
| children | 320e1d49aa9e e3ddbf7f2d3f |
comparison
equal
deleted
inserted
replaced
| 14144:e38916e22f59 | 14146:1d028f9473c2 |
|---|---|
| 436 function listener.ondisconnect(conn, err) | 436 function listener.ondisconnect(conn, err) |
| 437 local session = sessions[conn]; | 437 local session = sessions[conn]; |
| 438 if session then | 438 if session then |
| 439 (session.log or log)("info", "Client disconnected: %s", err or "connection closed"); | 439 (session.log or log)("info", "Client disconnected: %s", err or "connection closed"); |
| 440 stop_session_timers(session); | 440 stop_session_timers(session); |
| 441 sm_destroy_session(session, err); | 441 if not session.hibernating then |
| 442 sm_destroy_session(session, err); | |
| 443 end | |
| 442 session.conn = nil; | 444 session.conn = nil; |
| 443 sessions[conn] = nil; | 445 sessions[conn] = nil; |
| 444 end | 446 end |
| 445 module:fire_event("c2s-closed", { session = session; conn = conn }); | 447 module:fire_event("c2s-closed", { session = session; conn = conn }); |
| 446 end | 448 end |
