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

fix: check process alive before health check

EMQ-YangM 3 лет назад
Родитель
Сommit
c52b464b3c

+ 4 - 2
apps/emqx_plugin_libs/src/emqx_plugin_libs_pool.erl

@@ -68,8 +68,10 @@ get_status(PoolName, CheckFunc, AutoReconn) when is_function(CheckFunc) ->
     Status = [
         begin
             case ecpool_worker:client(Worker) of
-                {ok, Conn} -> CheckFunc(Conn);
-                _ -> false
+                {ok, Conn} ->
+                    erlang:is_process_alive(Conn) andalso CheckFunc(Conn);
+                _ ->
+                    false
             end
         end
      || {_WorkerName, Worker} <- ecpool:workers(PoolName)

+ 10 - 1
apps/emqx_resource/src/emqx_resource_health_check.erl

@@ -15,6 +15,8 @@
 %%--------------------------------------------------------------------
 -module(emqx_resource_health_check).
 
+-include_lib("emqx/include/logger.hrl").
+
 -export([
     start_link/3,
     create_checker/3,
@@ -98,7 +100,14 @@ health_check_timeout_checker(Pid, Name, SleepTime, Timeout) ->
             #{name => Name},
             <<Name/binary, " health check timeout">>
         ),
-        _ = emqx_resouce_instance:set_resource_status(Name, disconnected),
+        ?SLOG(
+            error,
+            #{
+                msg => "health check failed: timeout",
+                name => Name
+            }
+        ),
+        _ = emqx_resource_instance:set_resource_status(Name, disconnected),
         receive
             health_check_finish -> timer:sleep(SleepTime)
         end

+ 0 - 7
apps/emqx_resource/src/emqx_resource_instance.erl

@@ -345,13 +345,6 @@ do_set_resource_status_connecting(InstId) ->
 set_resource_status(InstId, Status) ->
     case lookup(InstId) of
         {ok, Group, #{id := _} = Data} ->
-            ?SLOG(
-                error,
-                #{
-                    msg => "health check failed: timeout",
-                    resource_id => InstId
-                }
-            ),
             update_resource(InstId, Group, Data#{status => Status});
         Error ->
             ?SLOG(