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 = [ Status = [
begin begin
case ecpool_worker:client(Worker) of case ecpool_worker:client(Worker) of
{ok, Conn} -> CheckFunc(Conn); {ok, Conn} ->
_ -> false erlang:is_process_alive(Conn) andalso CheckFunc(Conn);
_ ->
false
end end
end end
|| {_WorkerName, Worker} <- ecpool:workers(PoolName) || {_WorkerName, Worker} <- ecpool:workers(PoolName)

View File

@ -15,6 +15,8 @@
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
-module(emqx_resource_health_check). -module(emqx_resource_health_check).
-include_lib("emqx/include/logger.hrl").
-export([ -export([
start_link/3, start_link/3,
create_checker/3, create_checker/3,
@ -98,7 +100,14 @@ health_check_timeout_checker(Pid, Name, SleepTime, Timeout) ->
#{name => Name}, #{name => Name},
<<Name/binary, " health check timeout">> <<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 receive
health_check_finish -> timer:sleep(SleepTime) health_check_finish -> timer:sleep(SleepTime)
end end

View File

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