From ac8e4d98280d5a3fc050be2dc220016006fca96b Mon Sep 17 00:00:00 2001 From: damencho Date: Thu, 4 May 2023 14:41:09 -0500 Subject: [PATCH] fix: Fixes notifying vnodes to destroy rooms. It may happen we receive the disconnect iq after the main room is already destroyed. We now send disconnect on destroy to all vnodes or when receiving disconnect iq per vnode. --- resources/prosody-plugins/mod_visitors.lua | 18 +++++++++++++++++- .../prosody-plugins/mod_visitors_component.lua | 1 + 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/resources/prosody-plugins/mod_visitors.lua b/resources/prosody-plugins/mod_visitors.lua index 2bbe579ae9..148be429e1 100644 --- a/resources/prosody-plugins/mod_visitors.lua +++ b/resources/prosody-plugins/mod_visitors.lua @@ -138,6 +138,12 @@ module:hook('iq/host', stanza_handler, 10); -- an event received from visitors component, which receives iqs from jicofo local function disconnect_vnode(event) local room, vnode = event.room, event.vnode; + + if visitors_nodes[event.room.jid] == nil then + -- maybe the room was already destroyed and vnodes cleared + return; + end + local conference_service = muc_domain_prefix..'.'..vnode..'.meet.jitsi'; -- we are counting vnode main participants and we should be clearing it there @@ -236,7 +242,17 @@ process_host_module(main_muc_component_config, function(host_module, host) -- cleanup cache host_module:hook('muc-room-destroyed',function(event) - visitors_nodes[event.room.jid] = nil; + local room = event.room; + + -- room is destroyed let's disconnect all vnodes + if visitors_nodes[room.jid] then + local vnodes = visitors_nodes[room.jid].nodes; + for conference_service in pairs(vnodes) do + send_visitors_iq(conference_service, room, 'disconnect'); + end + + visitors_nodes[room.jid] = nil; + end end); -- detects new participants joining main room and sending them to the visitor nodes diff --git a/resources/prosody-plugins/mod_visitors_component.lua b/resources/prosody-plugins/mod_visitors_component.lua index 38128f6723..1365e8e2b7 100644 --- a/resources/prosody-plugins/mod_visitors_component.lua +++ b/resources/prosody-plugins/mod_visitors_component.lua @@ -128,6 +128,7 @@ local function stanza_handler(event) local room = get_room_from_jid(room_jid_match_rewrite(room_jid)); if not room then + -- this maybe as we receive the iq from jicofo after the room is already destroyed module:log('debug', 'No room found %s', room_jid); return; end