Software /
code /
prosody
Comparison
plugins/mod_c2s.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 | 12300:fb74ff16620c |
child | 12302:6a8c680b8677 |
comparison
equal
deleted
inserted
replaced
12300:fb74ff16620c | 12301:4f1fe6eb1ddb |
---|---|
14 local sessionmanager = require "core.sessionmanager"; | 14 local sessionmanager = require "core.sessionmanager"; |
15 local statsmanager = require "core.statsmanager"; | 15 local statsmanager = require "core.statsmanager"; |
16 local st = require "util.stanza"; | 16 local st = require "util.stanza"; |
17 local sm_new_session, sm_destroy_session = sessionmanager.new_session, sessionmanager.destroy_session; | 17 local sm_new_session, sm_destroy_session = sessionmanager.new_session, sessionmanager.destroy_session; |
18 local uuid_generate = require "util.uuid".generate; | 18 local uuid_generate = require "util.uuid".generate; |
19 local runner = require "util.async".runner; | 19 local async = require "util.async"; |
20 local runner = async.runner; | |
20 | 21 |
21 local tostring, type = tostring, type; | 22 local tostring, type = tostring, type; |
22 | 23 |
23 local xmlns_xmpp_streams = "urn:ietf:params:xml:ns:xmpp-streams"; | 24 local xmlns_xmpp_streams = "urn:ietf:params:xml:ns:xmpp-streams"; |
24 | 25 |
380 (session.log or log)("info", "Client disconnected: %s", err or "connection closed"); | 381 (session.log or log)("info", "Client disconnected: %s", err or "connection closed"); |
381 sm_destroy_session(session, err); | 382 sm_destroy_session(session, err); |
382 session.conn = nil; | 383 session.conn = nil; |
383 sessions[conn] = nil; | 384 sessions[conn] = nil; |
384 end | 385 end |
386 module:fire_event("c2s-closed", { session = session; conn = conn }); | |
385 end | 387 end |
386 | 388 |
387 function listener.onreadtimeout(conn) | 389 function listener.onreadtimeout(conn) |
388 local session = sessions[conn]; | 390 local session = sessions[conn]; |
389 if session then | 391 if session then |
429 pm.unregister_service(netservice.name, netservice); | 431 pm.unregister_service(netservice.name, netservice); |
430 end | 432 end |
431 end, -80); | 433 end, -80); |
432 | 434 |
433 module:hook("server-stopping", function(event) | 435 module:hook("server-stopping", function(event) |
436 local wait, done = async.waiter(); | |
437 module:hook("c2s-closed", function () | |
438 if next(sessions) == nil then done(); end | |
439 end) | |
440 | |
434 -- Close sessions | 441 -- Close sessions |
435 local reason = event.reason; | 442 local reason = event.reason; |
436 for _, session in pairs(sessions) do | 443 for _, session in pairs(sessions) do |
437 session:close{ condition = "system-shutdown", text = reason }; | 444 session:close{ condition = "system-shutdown", text = reason }; |
438 end | 445 end |
446 | |
447 -- Wait for them to close properly if they haven't already | |
448 if next(sessions) ~= nil then | |
449 add_task(stream_close_timeout+1, done); | |
450 module:log("info", "Waiting for sessions to close"); | |
451 wait(); | |
452 end | |
453 | |
439 end, -100); | 454 end, -100); |
440 | 455 |
441 | 456 |
442 | 457 |
443 module:provides("net", { | 458 module:provides("net", { |