From 74731a5816446326e069e85f374d7a5748332691 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Pawe=C5=82=20Chmielowski?= Date: Tue, 22 Jan 2019 14:22:15 +0100 Subject: [PATCH] Make sure that room_destroyed is called even when some code throws in terminate We observed that some code was throwing exception in muc_room:terminate() and that make this room not properly unregister itself from muc_online table. --- src/mod_muc_room.erl | 63 +++++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 30 deletions(-) diff --git a/src/mod_muc_room.erl b/src/mod_muc_room.erl index 282220431..8bbdd8d97 100644 --- a/src/mod_muc_room.erl +++ b/src/mod_muc_room.erl @@ -699,36 +699,39 @@ handle_info(_Info, StateName, StateData) -> {next_state, StateName, StateData}. terminate(Reason, _StateName, StateData) -> - ?INFO_MSG("Stopping MUC room ~s@~s", - [StateData#state.room, StateData#state.host]), - ReasonT = case Reason of - shutdown -> - <<"You are being removed from the room " - "because of a system shutdown">>; - _ -> <<"Room terminates">> - end, - Packet = #presence{ - type = unavailable, - sub_els = [#muc_user{items = [#muc_item{affiliation = none, - reason = ReasonT, - role = none}], - status_codes = [332,110]}]}, - maps:fold( - fun(LJID, Info, _) -> - Nick = Info#user.nick, - case Reason of - shutdown -> - send_wrapped(jid:replace_resource(StateData#state.jid, Nick), - Info#user.jid, Packet, - ?NS_MUCSUB_NODES_PARTICIPANTS, - StateData); - _ -> ok - end, - tab_remove_online_user(LJID, StateData) - end, [], get_users_and_subscribers(StateData)), - add_to_log(room_existence, stopped, StateData), - mod_muc:room_destroyed(StateData#state.host, StateData#state.room, self(), - StateData#state.server_host), + try + ?INFO_MSG("Stopping MUC room ~s@~s", + [StateData#state.room, StateData#state.host]), + ReasonT = case Reason of + shutdown -> + <<"You are being removed from the room " + "because of a system shutdown">>; + _ -> <<"Room terminates">> + end, + Packet = #presence{ + type = unavailable, + sub_els = [#muc_user{items = [#muc_item{affiliation = none, + reason = ReasonT, + role = none}], + status_codes = [332,110]}]}, + maps:fold( + fun(LJID, Info, _) -> + Nick = Info#user.nick, + case Reason of + shutdown -> + send_wrapped(jid:replace_resource(StateData#state.jid, Nick), + Info#user.jid, Packet, + ?NS_MUCSUB_NODES_PARTICIPANTS, + StateData); + _ -> ok + end, + tab_remove_online_user(LJID, StateData) + end, [], get_users_and_subscribers(StateData)), + add_to_log(room_existence, stopped, StateData), + after + mod_muc:room_destroyed(StateData#state.host, StateData#state.room, self(), + StateData#state.server_host) + end, ok. %%%---------------------------------------------------------------------- -- 2.40.0