Просмотр исходного кода

fix: ensure cluster link app can recover from init failure

Fixes EMQX-12868

If initial configuration for cluster link is incorrect, and local
cluster fails to establish a connection, an actor would crash on
startup which will lead to app supervisor crash, and removing of
cluster link config handler. This will make it impossible to remove or
update erroneous cluster link configuration.
Ivan Dyachkov 1 год назад
Родитель
Сommit
13ac854f45
1 измененных файлов с 11 добавлено и 1 удалено
  1. 11 1
      apps/emqx_cluster_link/src/emqx_cluster_link_router_syncer.erl

+ 11 - 1
apps/emqx_cluster_link/src/emqx_cluster_link_router_syncer.erl

@@ -170,12 +170,22 @@ start_link_client(Actor, LinkConf) ->
     Options = emqx_cluster_link_config:mk_emqtt_options(LinkConf),
     case emqtt:start_link(refine_client_options(Options, Actor)) of
         {ok, Pid} ->
-            case emqtt:connect(Pid) of
+            try emqtt:connect(Pid) of
                 {ok, _Props} ->
                     {ok, Pid};
                 Error ->
                     _ = flush_link_signal(Pid),
                     Error
+            catch
+                exit:Reason ->
+                    ?SLOG(error, #{
+                        msg => "failed_to_connect_to_cluster",
+                        reason => Reason,
+                        options => Options,
+                        actor => Actor
+                    }),
+                    _ = flush_link_signal(Pid),
+                    {error, failed_to_connect}
             end;
         Error ->
             Error