From fefadbcd177b0a3f759c721580255050e36a2b38 Mon Sep 17 00:00:00 2001 From: JianBo He Date: Tue, 9 Nov 2021 22:05:09 +0800 Subject: [PATCH] fix(emqx_stomp): fix hot-upgrade stopping listener failed When the upgrade is executed, all envs of plugins are cleared, which causes the listener of stomp to stop failing. This is only a temporary modification to ensure that the upgrade can be executed successfully. following fixes: https://github.com/emqx/emqx/pull/6105 --- apps/emqx_stomp/src/emqx_stomp.appup.src | 3 ++- apps/emqx_stomp/src/emqx_stomp.erl | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/apps/emqx_stomp/src/emqx_stomp.appup.src b/apps/emqx_stomp/src/emqx_stomp.appup.src index bf4603e52..5ce1f8bd3 100644 --- a/apps/emqx_stomp/src/emqx_stomp.appup.src +++ b/apps/emqx_stomp/src/emqx_stomp.appup.src @@ -2,7 +2,8 @@ {VSN, [{"4.3.1",[{load_module,emqx_stomp_connection,brutal_purge,soft_purge,[]}]}, {"4.3.0", - [{restart_application,emqx_stomp}]}, + [{restart_application,emqx_stomp}, + {apply,{emqx_stomp,force_clear_after_app_stoped,[]}}]}, {<<".*">>,[]}], [{"4.3.1",[{load_module,emqx_stomp_connection,brutal_purge,soft_purge,[]}]}, {"4.3.0", diff --git a/apps/emqx_stomp/src/emqx_stomp.erl b/apps/emqx_stomp/src/emqx_stomp.erl index 9eafe3cf7..b8a66009c 100644 --- a/apps/emqx_stomp/src/emqx_stomp.erl +++ b/apps/emqx_stomp/src/emqx_stomp.erl @@ -33,6 +33,8 @@ , stop_listener/3 ]). +-export([force_clear_after_app_stoped/0]). + -export([init/1]). -define(APP, ?MODULE). @@ -52,6 +54,18 @@ start(_StartType, _StartArgs) -> stop(_State) -> stop_listeners(). +force_clear_after_app_stoped() -> + lists:foreach(fun({Name = {ProtoName, _}, _}) -> + case is_stomp_listener(ProtoName) of + true -> esockd:close(Name); + _ -> ok + end + end, esockd:listeners()). + +is_stomp_listener('stomp:tcp') -> true; +is_stomp_listener('stomp:ssl') -> true; +is_stomp_listener(_) -> false. + %%-------------------------------------------------------------------- %% Supervisor callbacks %%--------------------------------------------------------------------