From b89b219406f266401c975c4745617ac35a0a9499 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 19 Jan 2023 21:38:14 +0100 Subject: core.sessionmanager: Skip log when (not) destroying destroyed sessions On regular disconnects, is sent, then sessionmanager.destroy_session() is called, then sessionmanager.destroy_session() is called again when the TCP connection is closed, from ondisconnect in mod_c2s. It is a bit annoying and doesn't really tell you much. --- core/sessionmanager.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'core') diff --git a/core/sessionmanager.lua b/core/sessionmanager.lua index 7f296ff1..60135e1f 100644 --- a/core/sessionmanager.lua +++ b/core/sessionmanager.lua @@ -93,12 +93,11 @@ local function retire_session(session) end local function destroy_session(session, err) + if session.destroyed then return; end (session.log or log)("debug", "Destroying session for %s (%s@%s)%s", session.full_jid or "(unknown)", session.username or "(unknown)", session.host or "(unknown)", err and (": "..err) or ""); - if session.destroyed then return; end - -- Remove session/resource from user's session list if session.full_jid then local host_session = hosts[session.host]; -- cgit v1.2.3 From d616d70f3c7b9cb76a488ef69173d6340131bd62 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 19 Jan 2023 21:40:09 +0100 Subject: core.sessionmanager: Mark session as destroyed to prevent reentry If it reaches this point, then the session will be most definitely be destroyed, so try to prevent destroy_session() from being called again. --- core/sessionmanager.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'core') diff --git a/core/sessionmanager.lua b/core/sessionmanager.lua index 60135e1f..ecc829e4 100644 --- a/core/sessionmanager.lua +++ b/core/sessionmanager.lua @@ -106,6 +106,7 @@ local function destroy_session(session, err) if host_session.events.fire_event("pre-resource-unbind", {session=session, error=err}) then return; end + session.destroyed = true; -- Past this point the session is DOOMED! host_session.sessions[session.username].sessions[session.resource] = nil; full_sessions[session.full_jid] = nil; -- cgit v1.2.3 From a4556fc67aa2036bc0f7d95d5f61ba7e95412304 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 9 Feb 2023 15:09:03 +0000 Subject: sessionmanager: Improve logging around session destruction --- core/sessionmanager.lua | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'core') diff --git a/core/sessionmanager.lua b/core/sessionmanager.lua index ecc829e4..f8279bb4 100644 --- a/core/sessionmanager.lua +++ b/core/sessionmanager.lua @@ -94,9 +94,6 @@ end local function destroy_session(session, err) if session.destroyed then return; end - (session.log or log)("debug", "Destroying session for %s (%s@%s)%s", - session.full_jid or "(unknown)", session.username or "(unknown)", - session.host or "(unknown)", err and (": "..err) or ""); -- Remove session/resource from user's session list if session.full_jid then @@ -104,8 +101,14 @@ local function destroy_session(session, err) -- Allow plugins to prevent session destruction if host_session.events.fire_event("pre-resource-unbind", {session=session, error=err}) then + (session.log or log)("debug", "Resource unbind prevented by module"); return; end + + (session.log or log)("debug", "Unbinding resource for %s (%s@%s)%s", + session.full_jid or "(unknown)", session.username or "(unknown)", + session.host or "(unknown)", err and (": "..err) or ""); + session.destroyed = true; -- Past this point the session is DOOMED! host_session.sessions[session.username].sessions[session.resource] = nil; @@ -118,6 +121,10 @@ local function destroy_session(session, err) end host_session.events.fire_event("resource-unbind", {session=session, error=err}); + else + (session.log or log)("debug", "Destroying unbound session for <%s@%s>%s", + session.username or "(unknown)", session.host or "(unknown)", + err and (": "..err) or ""); end retire_session(session); -- cgit v1.2.3