mirror of
https://github.com/bjc/prosody.git
synced 2025-04-03 21:27:38 +03:00
Fix for not destroying sessions when connection closed.
This commit is contained in:
parent
b13393bcd9
commit
ff0fe0544a
2 changed files with 18 additions and 9 deletions
|
@ -19,21 +19,22 @@ local getmetatable = getmetatable;
|
|||
|
||||
module "sessionmanager"
|
||||
|
||||
local open_sessions = 0;
|
||||
|
||||
function new_session(conn)
|
||||
local session = { conn = conn, priority = 0, type = "c2s_unauthed" };
|
||||
if true then
|
||||
session.trace = newproxy(true);
|
||||
getmetatable(session.trace).__gc = function () print("Session got collected") end;
|
||||
getmetatable(session.trace).__gc = function () open_sessions = open_sessions - 1; print("Session got collected, now "..open_sessions.." sessions are allocated") end;
|
||||
end
|
||||
open_sessions = open_sessions + 1;
|
||||
local w = conn.write;
|
||||
session.send = function (t) w(tostring(t)); end
|
||||
return session;
|
||||
end
|
||||
|
||||
function destroy_session(session)
|
||||
if not (session and session.disconnect) then return; end
|
||||
log("debug", "Destroying session...");
|
||||
session.disconnect();
|
||||
session.log("info", "Destroying session");
|
||||
if session.username then
|
||||
if session.resource then
|
||||
hosts[session.host].sessions[session.username].sessions[session.resource] = nil;
|
||||
|
@ -53,11 +54,6 @@ function destroy_session(session)
|
|||
session[k] = nil;
|
||||
end
|
||||
end
|
||||
collectgarbage("collect");
|
||||
collectgarbage("collect");
|
||||
collectgarbage("collect");
|
||||
collectgarbage("collect");
|
||||
collectgarbage("collect");
|
||||
end
|
||||
|
||||
function send_to_session(session, data)
|
||||
|
|
|
@ -69,6 +69,19 @@ function xmppclient.listener(conn, data)
|
|||
end
|
||||
|
||||
function xmppclient.disconnect(conn)
|
||||
local session = sessions[conn];
|
||||
if session then
|
||||
if session.last_presence and session.last_presence.attr.type ~= "unavailable" then
|
||||
local pres = st.presence{ type = "unavailable" };
|
||||
if err == "closed" then err = "connection closed"; end
|
||||
pres:tag("status"):text("Disconnected: "..err);
|
||||
session.stanza_dispatch(pres);
|
||||
end
|
||||
sm_destroy_session(session);
|
||||
sessions[conn] = nil;
|
||||
session = nil;
|
||||
collectgarbage("collect");
|
||||
end
|
||||
end
|
||||
|
||||
connlisteners_register("xmppclient", xmppclient);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue