Comparison

plugins/mod_s2s.lua @ 12301:4f1fe6eb1ddb

mod_c2s,mod_s2s: Wait for sessions to close before proceeding with shutdown steps Ensures unavailable presence and other outgoing stanzas are sent. Waiting for c2s sessions to close first before proceeding to disable and close s2s ensures that unavailable presence can go out, even if it requires dialback to complete first.
author Kim Alvefur <zash@zash.se>
date Thu, 17 Feb 2022 03:49:47 +0100
parent 12299:ff36ac5c7d2b
child 12309:926a6c5d13e7
child 12330:38b5b05407be
comparison
equal deleted inserted replaced
12300:fb74ff16620c 12301:4f1fe6eb1ddb
24 local new_xmpp_stream = require "util.xmppstream".new; 24 local new_xmpp_stream = require "util.xmppstream".new;
25 local s2s_new_incoming = require "core.s2smanager".new_incoming; 25 local s2s_new_incoming = require "core.s2smanager".new_incoming;
26 local s2s_new_outgoing = require "core.s2smanager".new_outgoing; 26 local s2s_new_outgoing = require "core.s2smanager".new_outgoing;
27 local s2s_destroy_session = require "core.s2smanager".destroy_session; 27 local s2s_destroy_session = require "core.s2smanager".destroy_session;
28 local uuid_gen = require "util.uuid".generate; 28 local uuid_gen = require "util.uuid".generate;
29 local runner = require "util.async".runner; 29 local async = require "util.async";
30 local runner = async.runner;
30 local connect = require "net.connect".connect; 31 local connect = require "net.connect".connect;
31 local service = require "net.resolvers.service"; 32 local service = require "net.resolvers.service";
32 local resolver_chain = require "net.resolvers.chain"; 33 local resolver_chain = require "net.resolvers.chain";
33 local errors = require "util.error"; 34 local errors = require "util.error";
34 local set = require "util.set"; 35 local set = require "util.set";
857 -- TODO util.error-ify this 858 -- TODO util.error-ify this
858 err = "Error during negotiation of encrypted connection: "..err; 859 err = "Error during negotiation of encrypted connection: "..err;
859 end 860 end
860 s2s_destroy_session(session, err); 861 s2s_destroy_session(session, err);
861 end 862 end
863 module:fire_event("s2s-closed", { session = session; conn = conn });
862 end 864 end
863 865
864 function listener.onfail(data, err) 866 function listener.onfail(data, err)
865 local session = data and data.session; 867 local session = data and data.session;
866 if session then 868 if session then
969 if prosody.hosts[host].modules.s2s then 971 if prosody.hosts[host].modules.s2s then
970 module:context(host):unhook("route/remote", route_to_new_session); 972 module:context(host):unhook("route/remote", route_to_new_session);
971 end 973 end
972 end 974 end
973 975
976 local wait, done = async.waiter();
977 module:hook("s2s-closed", function ()
978 if next(sessions) == nil then done(); end
979 end, 1)
980
974 -- Close sessions 981 -- Close sessions
975 local reason = event.reason; 982 local reason = event.reason;
976 for _, session in pairs(sessions) do 983 for _, session in pairs(sessions) do
977 session:close{ condition = "system-shutdown", text = reason }; 984 session:close{ condition = "system-shutdown", text = reason };
978 end 985 end
986
987 -- Wait for them to close properly if they haven't already
988 if next(sessions) ~= nil then
989 module:log("info", "Waiting for sessions to close");
990 add_task(stream_close_timeout + 1, done);
991 wait();
992 end
993
979 end, -200); 994 end, -200);
980 995
981 996
982 997
983 module:provides("net", { 998 module:provides("net", {