fix(authn): create authn chain tab in start_link
This commit is contained in:
parent
fc7eb21083
commit
3d449b5acf
|
@ -277,6 +277,9 @@ initialize_authentication(ChainName, AuthenticatorsConfig) ->
|
||||||
|
|
||||||
-spec start_link() -> {ok, pid()} | ignore | {error, term()}.
|
-spec start_link() -> {ok, pid()} | ignore | {error, term()}.
|
||||||
start_link() ->
|
start_link() ->
|
||||||
|
%% Create chains ETS table here so that it belongs to the supervisor
|
||||||
|
%% and survives `emqx_authentication` crashes.
|
||||||
|
ok = create_chain_table(),
|
||||||
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
|
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
|
||||||
|
|
||||||
-spec stop() -> ok.
|
-spec stop() -> ok.
|
||||||
|
@ -401,7 +404,6 @@ list_users(ChainName, AuthenticatorID, Params) ->
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
|
||||||
init(_Opts) ->
|
init(_Opts) ->
|
||||||
ok = create_chain_table(),
|
|
||||||
ok = emqx_config_handler:add_handler([authentication], ?MODULE),
|
ok = emqx_config_handler:add_handler([authentication], ?MODULE),
|
||||||
ok = emqx_config_handler:add_handler([listeners, '?', '?', authentication], ?MODULE),
|
ok = emqx_config_handler:add_handler([listeners, '?', '?', authentication], ?MODULE),
|
||||||
{ok, #{hooked => false, providers => #{}}}.
|
{ok, #{hooked => false, providers => #{}}}.
|
||||||
|
@ -581,21 +583,13 @@ reply(Reply, State) ->
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
|
||||||
create_chain_table() ->
|
create_chain_table() ->
|
||||||
Status = try
|
try
|
||||||
_ = ets:new(?CHAINS_TAB, [named_table, set, public,
|
_ = ets:new(?CHAINS_TAB, [named_table, set, public,
|
||||||
{keypos, #chain.name},
|
{keypos, #chain.name},
|
||||||
{read_concurrency, true}]),
|
{read_concurrency, true}]),
|
||||||
created
|
ok
|
||||||
catch
|
catch
|
||||||
error:badarg -> already_exists
|
error:badarg -> ok
|
||||||
end,
|
|
||||||
|
|
||||||
case Status of
|
|
||||||
created ->
|
|
||||||
ets:give_away(?CHAINS_TAB, whereis(emqx_authentication_sup), undefined),
|
|
||||||
ok;
|
|
||||||
already_exists ->
|
|
||||||
ok
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
global_chain(mqtt) ->
|
global_chain(mqtt) ->
|
||||||
|
|
Loading…
Reference in New Issue