Skip to content

Commit

Permalink
feat: Adds detection of occupants with no connection.
Browse files Browse the repository at this point in the history
We saw recently two occasions with rooms with participants but no prosody.full_sessions for those participants and when everyone leaves the meeting it never ends.
  • Loading branch information
damencho committed Dec 12, 2023
1 parent 72b4c81 commit b085f3b
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions resources/prosody-plugins/mod_muc_census.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ local tostring = tostring;
-- required parameter for custom muc component prefix, defaults to "conference"
local muc_domain_prefix = module:get_option_string("muc_mapper_domain_prefix", "conference");

local leaked_rooms_since_last_stat = 0;

--- handles request to get number of participants in all rooms
-- @return GET response
function handle_get_room_census(event)
Expand All @@ -49,15 +51,33 @@ function handle_get_room_census(event)
for room in host_session.modules.muc.each_room() do
if not is_healthcheck_room(room.jid) then
local occupants = room._occupants;
local participant_count = 0;
local missing_connections_count = 0;

if occupants then
participant_count = iterators.count(room:each_occupant()) - 1; -- subtract focus
else
participant_count = 0
for _, o in room:each_occupant() do
participant_count = participant_count + 1;

-- let's check whether that occupant has connection in the full_sessions of prosody
-- attempt to detect leaked occupants/rooms.
if prosody.full_sessions[o.jid] == nil then
missing_connections_count = missing_connections_count + 1;
end
end
participant_count = participant_count - 1; -- subtract focus
end

local leaked = false;
if participant_count > 0 and missing_connections_count == participant_count then
leaked = true;
leaked_rooms_since_last_stat = leaked_rooms_since_last_stat + 1;
end

table.insert(room_data, {
room_name = room.jid;
participants = participant_count;
created_time = room.created_timestamp;
leaked = leaked;
});
end
end
Expand All @@ -77,3 +97,10 @@ function module.load()
};
});
end

-- we calculate the stats on the configured interval (60 seconds by default)
local measure_leaked_rooms = module:measure('leaked_rooms', 'amount');
module:hook_global('stats-update', function ()
measure_leaked_rooms(leaked_rooms_since_last_stat);
leaked_rooms_since_last_stat = 0;
end);

0 comments on commit b085f3b

Please sign in to comment.