소스 검색

Merge pull request #7764 from HJianBo/fix-authn-proc-crash

fix(authn): avoid crashing emqx_authentication process due to un-safe call
JianBo He 3 년 전
부모
커밋
81e9000c72
1개의 변경된 파일7개의 추가작업 그리고 1개의 파일을 삭제
  1. 7 1
      apps/emqx/src/emqx_authentication.erl

+ 7 - 1
apps/emqx/src/emqx_authentication.erl

@@ -417,6 +417,7 @@ list_users(ChainName, AuthenticatorID, FuzzyParams) ->
 %%--------------------------------------------------------------------
 %%--------------------------------------------------------------------
 
 
 init(_Opts) ->
 init(_Opts) ->
+    process_flag(trap_exit, true),
     ok = emqx_config_handler:add_handler([?CONF_ROOT], ?MODULE),
     ok = emqx_config_handler:add_handler([?CONF_ROOT], ?MODULE),
     ok = emqx_config_handler:add_handler([listeners, '?', '?', ?CONF_ROOT], ?MODULE),
     ok = emqx_config_handler:add_handler([listeners, '?', '?', ?CONF_ROOT], ?MODULE),
     {ok, #{hooked => false, providers => #{}}}.
     {ok, #{hooked => false, providers => #{}}}.
@@ -784,7 +785,12 @@ update_chain(ChainName, UpdateFun) ->
         [] ->
         [] ->
             {error, {not_found, {chain, ChainName}}};
             {error, {not_found, {chain, ChainName}}};
         [Chain] ->
         [Chain] ->
-            UpdateFun(Chain)
+            try
+                UpdateFun(Chain)
+            catch
+                Class:Reason:Stk ->
+                    {error, {exception, {Class, Reason, Stk}}}
+            end
     end.
     end.
 
 
 call_authenticator(ChainName, AuthenticatorID, Func, Args) ->
 call_authenticator(ChainName, AuthenticatorID, Func, Args) ->