fix: catch errors when load bridges

This commit is contained in:
Shawn 2022-06-10 14:31:48 +08:00
parent 8518e71db1
commit dd099137f0
3 changed files with 29 additions and 11 deletions

View File

@ -508,10 +508,10 @@ handle_info(Info, State) ->
terminate(Reason, _State) ->
case Reason of
normal ->
ok;
{shutdown, _} ->
ok;
Reason when Reason == normal; Reason == shutdown ->
ok;
Other ->
?SLOG(error, #{
msg => "emqx_authentication_terminating",

View File

@ -55,6 +55,16 @@ load() ->
fun({Type, NamedConf}) ->
lists:foreach(
fun({Name, Conf}) ->
safe_load_bridge(Type, Name, Conf, Opts)
end,
maps:to_list(NamedConf)
)
end,
maps:to_list(Bridges)
).
safe_load_bridge(Type, Name, Conf, Opts) ->
try
_Res = emqx_bridge_resource:create(Type, Name, Conf, Opts),
?tp(
emqx_bridge_loaded,
@ -64,12 +74,17 @@ load() ->
res => _Res
}
)
end,
maps:to_list(NamedConf)
)
end,
maps:to_list(Bridges)
).
catch
Err:Reason:ST ->
?SLOG(error, #{
msg => "load_bridge_failed",
type => Type,
name => Name,
error => Err,
reason => Reason,
stacktrace => ST
})
end.
load_hook() ->
Bridges = emqx:get_config([bridges], #{}),

View File

@ -571,6 +571,9 @@ pick_bridges_by_id(Type, Name, BridgesAllNodes) ->
[] ->
?SLOG(warning, #{
msg => "bridge_inconsistent_in_cluster",
reason => not_found,
type => Type,
name => Name,
bridge => emqx_bridge_resource:bridge_id(Type, Name)
}),
Acc