]> granicus.if.org Git - ejabberd/commitdiff
Make sure that room_destroyed is called even when some code throws in terminate
authorPaweł Chmielowski <pchmielowski@process-one.net>
Tue, 22 Jan 2019 13:22:15 +0000 (14:22 +0100)
committerPaweł Chmielowski <pchmielowski@process-one.net>
Tue, 22 Jan 2019 13:22:23 +0000 (14:22 +0100)
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

index 2822204317ba01f75b326e0965a597ff4dc8e116..8bbdd8d9705c25ec1ceabee353b33568ca4d83a9 100644 (file)
@@ -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.
 
 %%%----------------------------------------------------------------------