Software /
code /
prosody
Comparison
core/s2smanager.lua @ 2746:3b9547fc0bed
sessionmanager, s2smanager: Destroyed sessions are now simply resting (not dead) until they are collected - prevents a whole class of tracebacks
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Mon, 08 Mar 2010 02:13:41 +0000 |
parent | 2714:9c5d8e0c146e |
child | 2747:168104895051 |
comparison
equal
deleted
inserted
replaced
2745:5cedad1bcb28 | 2746:3b9547fc0bed |
---|---|
14 local add_task = require "util.timer".add_task; | 14 local add_task = require "util.timer".add_task; |
15 local socket = require "socket"; | 15 local socket = require "socket"; |
16 local format = string.format; | 16 local format = string.format; |
17 local t_insert, t_sort = table.insert, table.sort; | 17 local t_insert, t_sort = table.insert, table.sort; |
18 local get_traceback = debug.traceback; | 18 local get_traceback = debug.traceback; |
19 local tostring, pairs, ipairs, getmetatable, newproxy, error, tonumber | 19 local tostring, pairs, ipairs, getmetatable, newproxy, error, tonumber, |
20 = tostring, pairs, ipairs, getmetatable, newproxy, error, tonumber; | 20 setmetatable |
21 = tostring, pairs, ipairs, getmetatable, newproxy, error, tonumber, | |
22 setmetatable; | |
21 | 23 |
22 local idna_to_ascii = require "util.encodings".idna.to_ascii; | 24 local idna_to_ascii = require "util.encodings".idna.to_ascii; |
23 local connlisteners_get = require "net.connlisteners".get; | 25 local connlisteners_get = require "net.connlisteners".get; |
24 local wrapclient = require "net.server".wrapclient; | 26 local wrapclient = require "net.server".wrapclient; |
25 local modulemanager = require "core.modulemanager"; | 27 local modulemanager = require "core.modulemanager"; |
508 | 510 |
509 session.srv_hosts = nil; | 511 session.srv_hosts = nil; |
510 end | 512 end |
511 end | 513 end |
512 | 514 |
513 local function null_data_handler(conn, data) log("debug", "Discarding data from destroyed s2s session: %s", data); end | 515 local resting_session = { -- Resting, not dead |
516 destroyed = true; | |
517 }; resting_session.__index = resting_session; | |
518 | |
519 function retire_session(session) | |
520 local log = session.log or log; | |
521 for k in pairs(session) do | |
522 if k ~= "trace" and k ~= "log" and k ~= "id" then | |
523 session[k] = nil; | |
524 end | |
525 end | |
526 | |
527 function session.send(data) log("debug", "Discarding data sent to resting session: %s", tostring(data)); end | |
528 function session.data(data) log("debug", "Discarding data received from resting session: %s", tostring(data)); end | |
529 return setmetatable(session, resting_session); | |
530 end | |
514 | 531 |
515 function destroy_session(session, reason) | 532 function destroy_session(session, reason) |
516 (session.log or log)("info", "Destroying "..tostring(session.direction).." session "..tostring(session.from_host).."->"..tostring(session.to_host)); | 533 (session.log or log)("info", "Destroying "..tostring(session.direction).." session "..tostring(session.from_host).."->"..tostring(session.to_host)); |
517 | 534 |
518 if session.direction == "outgoing" then | 535 if session.direction == "outgoing" then |
520 bounce_sendq(session, reason); | 537 bounce_sendq(session, reason); |
521 elseif session.direction == "incoming" then | 538 elseif session.direction == "incoming" then |
522 incoming_s2s[session] = nil; | 539 incoming_s2s[session] = nil; |
523 end | 540 end |
524 | 541 |
525 for k in pairs(session) do | 542 retire_session(session); -- Clean session until it is GC'd |
526 if k ~= "trace" then | |
527 session[k] = nil; | |
528 end | |
529 end | |
530 session.data = null_data_handler; | |
531 end | 543 end |
532 | 544 |
533 return _M; | 545 return _M; |