Comparison

core/sessionmanager.lua @ 12879:09a53ed8f4d5 0.12

sessionmanager: Improve logging around session destruction
author Matthew Wild <mwild1@gmail.com>
date Thu, 09 Feb 2023 15:09:03 +0000
parent 12878:0d8bf401fa73
child 12880:b56a2731bf00
comparison
equal deleted inserted replaced
12878:0d8bf401fa73 12879:09a53ed8f4d5
92 return setmetatable(session, resting_session); 92 return setmetatable(session, resting_session);
93 end 93 end
94 94
95 local function destroy_session(session, err) 95 local function destroy_session(session, err)
96 if session.destroyed then return; end 96 if session.destroyed then return; end
97 (session.log or log)("debug", "Destroying session for %s (%s@%s)%s",
98 session.full_jid or "(unknown)", session.username or "(unknown)",
99 session.host or "(unknown)", err and (": "..err) or "");
100 97
101 -- Remove session/resource from user's session list 98 -- Remove session/resource from user's session list
102 if session.full_jid then 99 if session.full_jid then
103 local host_session = hosts[session.host]; 100 local host_session = hosts[session.host];
104 101
105 -- Allow plugins to prevent session destruction 102 -- Allow plugins to prevent session destruction
106 if host_session.events.fire_event("pre-resource-unbind", {session=session, error=err}) then 103 if host_session.events.fire_event("pre-resource-unbind", {session=session, error=err}) then
104 (session.log or log)("debug", "Resource unbind prevented by module");
107 return; 105 return;
108 end 106 end
107
108 (session.log or log)("debug", "Unbinding resource for %s (%s@%s)%s",
109 session.full_jid or "(unknown)", session.username or "(unknown)",
110 session.host or "(unknown)", err and (": "..err) or "");
111
109 session.destroyed = true; -- Past this point the session is DOOMED! 112 session.destroyed = true; -- Past this point the session is DOOMED!
110 113
111 host_session.sessions[session.username].sessions[session.resource] = nil; 114 host_session.sessions[session.username].sessions[session.resource] = nil;
112 full_sessions[session.full_jid] = nil; 115 full_sessions[session.full_jid] = nil;
113 116
116 host_session.sessions[session.username] = nil; 119 host_session.sessions[session.username] = nil;
117 bare_sessions[session.username..'@'..session.host] = nil; 120 bare_sessions[session.username..'@'..session.host] = nil;
118 end 121 end
119 122
120 host_session.events.fire_event("resource-unbind", {session=session, error=err}); 123 host_session.events.fire_event("resource-unbind", {session=session, error=err});
124 else
125 (session.log or log)("debug", "Destroying unbound session for <%s@%s>%s",
126 session.username or "(unknown)", session.host or "(unknown)",
127 err and (": "..err) or "");
121 end 128 end
122 129
123 retire_session(session); 130 retire_session(session);
124 end 131 end
125 132