fix: check process alive before health check

This commit is contained in:
EMQ-YangM 2022-04-29 17:07:42 +08:00
parent 1bf33f75cc
commit c52b464b3c
3 changed files with 14 additions and 10 deletions

View File

@ -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)

View File

@ -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

View File

@ -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(