From 7b445486a0173b2d2b96e5639de02d81fc10a0f8 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 8 Mar 2010 02:13:41 +0000 Subject: sessionmanager, s2smanager: Destroyed sessions are now simply resting (not dead) until they are collected - prevents a whole class of tracebacks --- core/s2smanager.lua | 30 +++++++++++++++++++++--------- core/sessionmanager.lua | 26 ++++++++++++++++++-------- 2 files changed, 39 insertions(+), 17 deletions(-) (limited to 'core') diff --git a/core/s2smanager.lua b/core/s2smanager.lua index 16ede7b6..0435bea9 100644 --- a/core/s2smanager.lua +++ b/core/s2smanager.lua @@ -16,8 +16,10 @@ local socket = require "socket"; local format = string.format; local t_insert, t_sort = table.insert, table.sort; local get_traceback = debug.traceback; -local tostring, pairs, ipairs, getmetatable, newproxy, error, tonumber - = tostring, pairs, ipairs, getmetatable, newproxy, error, tonumber; +local tostring, pairs, ipairs, getmetatable, newproxy, error, tonumber, + setmetatable + = tostring, pairs, ipairs, getmetatable, newproxy, error, tonumber, + setmetatable; local idna_to_ascii = require "util.encodings".idna.to_ascii; local connlisteners_get = require "net.connlisteners".get; @@ -510,7 +512,22 @@ function mark_connected(session) end end -local function null_data_handler(conn, data) log("debug", "Discarding data from destroyed s2s session: %s", data); end +local resting_session = { -- Resting, not dead + destroyed = true; + }; resting_session.__index = resting_session; + +function retire_session(session) + local log = session.log or log; + for k in pairs(session) do + if k ~= "trace" and k ~= "log" and k ~= "id" then + session[k] = nil; + end + end + + function session.send(data) log("debug", "Discarding data sent to resting session: %s", tostring(data)); end + function session.data(data) log("debug", "Discarding data received from resting session: %s", tostring(data)); end + return setmetatable(session, resting_session); +end function destroy_session(session, reason) (session.log or log)("info", "Destroying "..tostring(session.direction).." session "..tostring(session.from_host).."->"..tostring(session.to_host)); @@ -522,12 +539,7 @@ function destroy_session(session, reason) incoming_s2s[session] = nil; end - for k in pairs(session) do - if k ~= "trace" then - session[k] = nil; - end - end - session.data = null_data_handler; + retire_session(session); -- Clean session until it is GC'd end return _M; diff --git a/core/sessionmanager.lua b/core/sessionmanager.lua index 29adcfbb..a2c6ed95 100644 --- a/core/sessionmanager.lua +++ b/core/sessionmanager.lua @@ -8,7 +8,7 @@ -local tonumber, tostring = tonumber, tostring; +local tonumber, tostring, setmetatable = tonumber, tostring, setmetatable; local ipairs, pairs, print, next= ipairs, pairs, print, next; local format = import("string", "format"); @@ -66,7 +66,22 @@ function new_session(conn) return session; end -local function null_data_handler(conn, data) log("debug", "Discarding data from destroyed c2s session: %s", data); end +local resting_session = { -- Resting, not dead + destroyed = true; + }; resting_session.__index = resting_session; + +function retire_session(session) + local log = session.log or log; + for k in pairs(session) do + if k ~= "trace" and k ~= "log" and k ~= "id" then + session[k] = nil; + end + end + + function session.send(data) log("debug", "Discarding data sent to resting session: %s", tostring(data)); end + function session.data(data) log("debug", "Discarding data received from resting session: %s", tostring(data)); end + return setmetatable(session, resting_session); +end function destroy_session(session, err) (session.log or log)("info", "Destroying session for %s (%s@%s)", session.full_jid or "(unknown)", session.username or "(unknown)", session.host or "(unknown)"); @@ -85,12 +100,7 @@ function destroy_session(session, err) hosts[session.host].events.fire_event("resource-unbind", {session=session, error=err}); end - for k in pairs(session) do - if k ~= "trace" then - session[k] = nil; - end - end - session.data = null_data_handler; + retire_session(session); end function make_authenticated(session, username) -- cgit v1.2.3 From 8e4f70c4a2db2fd6e2a35ebefd63a9177b44fc31 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 11 Mar 2010 01:04:19 +0000 Subject: sessionmanager, s2smanager: Close session on --- core/s2smanager.lua | 7 ++----- core/sessionmanager.lua | 4 ++-- 2 files changed, 4 insertions(+), 7 deletions(-) (limited to 'core') diff --git a/core/s2smanager.lua b/core/s2smanager.lua index 0435bea9..15d981d4 100644 --- a/core/s2smanager.lua +++ b/core/s2smanager.lua @@ -434,11 +434,8 @@ function streamopened(session, attr) end function streamclosed(session) - (session.log or log)("debug", ""); - if session.sends2s then - session.sends2s(""); - end - session.notopen = true; + (session.log or log)("debug", "Received "); + session:close(); end function initiate_dialback(session) diff --git a/core/sessionmanager.lua b/core/sessionmanager.lua index a2c6ed95..b65e866f 100644 --- a/core/sessionmanager.lua +++ b/core/sessionmanager.lua @@ -211,8 +211,8 @@ function streamopened(session, attr) end function streamclosed(session) - session.send(""); - session.notopen = true; + session.log("debug", "Received "); + session:close(); end function send_to_available_resources(user, host, stanza) -- cgit v1.2.3 From 82d5e5fd0ce5e5c7682d8f0211a352fd8bd97efd Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 14 Mar 2010 02:56:57 +0000 Subject: s2smanager: Add open_stream and close methods to resting sessions --- core/s2smanager.lua | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'core') diff --git a/core/s2smanager.lua b/core/s2smanager.lua index 15d981d4..ccd8161f 100644 --- a/core/s2smanager.lua +++ b/core/s2smanager.lua @@ -511,6 +511,12 @@ end local resting_session = { -- Resting, not dead destroyed = true; + open_stream = function (session) + session.log("debug", "Attempt to open stream on resting session"); + end; + close = function (session) + session.log("debug", "Attempt to close already-closed session"); + end; }; resting_session.__index = resting_session; function retire_session(session) -- cgit v1.2.3 From 03734de797479ba2cf10002df6a040b6f7d0c010 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 14 Mar 2010 02:57:22 +0000 Subject: s2smanager: Don't re-destroy destroyed sessions --- core/s2smanager.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'core') diff --git a/core/s2smanager.lua b/core/s2smanager.lua index ccd8161f..b65fe00c 100644 --- a/core/s2smanager.lua +++ b/core/s2smanager.lua @@ -533,6 +533,7 @@ function retire_session(session) end function destroy_session(session, reason) + if session.destroyed then return; end (session.log or log)("info", "Destroying "..tostring(session.direction).." session "..tostring(session.from_host).."->"..tostring(session.to_host)); if session.direction == "outgoing" then -- cgit v1.2.3 From 8b94f4df2504444121a345c430538b0a409e059d Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 14 Mar 2010 02:58:11 +0000 Subject: sessionmanager: Add close method to resting sessions --- core/sessionmanager.lua | 3 +++ 1 file changed, 3 insertions(+) (limited to 'core') diff --git a/core/sessionmanager.lua b/core/sessionmanager.lua index b65e866f..5c40f756 100644 --- a/core/sessionmanager.lua +++ b/core/sessionmanager.lua @@ -68,6 +68,9 @@ end local resting_session = { -- Resting, not dead destroyed = true; + close = function (session) + session.log("debug", "Attempt to close already-closed session"); + end; }; resting_session.__index = resting_session; function retire_session(session) -- cgit v1.2.3 From c42dd4c96236f0b83654d83613d7d3cf5dffef84 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 14 Mar 2010 02:59:16 +0000 Subject: sessionmanager: Return stream error when incoming stream header is missing 'to' attribute --- core/sessionmanager.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'core') diff --git a/core/sessionmanager.lua b/core/sessionmanager.lua index 5c40f756..264c296b 100644 --- a/core/sessionmanager.lua +++ b/core/sessionmanager.lua @@ -181,7 +181,12 @@ end function streamopened(session, attr) local send = session.send; - session.host = attr.to or error("Client failed to specify destination hostname"); + session.host = attr.to; + if not session.host then + session:close{ condition = "improper-addressing", + text = "A 'to' attribute is required on stream headers" }; + return; + end session.host = nameprep(session.host); session.version = tonumber(attr.version) or 0; session.streamid = uuid_generate(); -- cgit v1.2.3 From 415ac76d286a0488bf65ae07b43f4d1b2c27aa75 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 14 Mar 2010 02:59:41 +0000 Subject: sessionmanager: Don't re-destroy destroyed sessions --- core/sessionmanager.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'core') diff --git a/core/sessionmanager.lua b/core/sessionmanager.lua index 264c296b..5fa757d6 100644 --- a/core/sessionmanager.lua +++ b/core/sessionmanager.lua @@ -88,6 +88,7 @@ end function destroy_session(session, err) (session.log or log)("info", "Destroying session for %s (%s@%s)", session.full_jid or "(unknown)", session.username or "(unknown)", session.host or "(unknown)"); + if session.destroyed then return; end -- Remove session/resource from user's session list if session.full_jid then -- cgit v1.2.3