Merge pull request #7108 from thalesmg/fix-sys-mon-portinfo
fix(sys_mon): guard before calling `erlang:port_info`
This commit is contained in:
commit
8d26ba6e9f
|
@ -202,7 +202,12 @@ get_proc_lib_initial_call(Pid) ->
|
||||||
end.
|
end.
|
||||||
|
|
||||||
portinfo(Port) ->
|
portinfo(Port) ->
|
||||||
[{port, Port} | erlang:port_info(Port)].
|
PortInfo =
|
||||||
|
case is_port(Port) andalso erlang:port_info(Port) of
|
||||||
|
L when is_list(L) -> L;
|
||||||
|
_ -> []
|
||||||
|
end,
|
||||||
|
[{port, Port} | PortInfo].
|
||||||
|
|
||||||
safe_publish(Event, WarnMsg) ->
|
safe_publish(Event, WarnMsg) ->
|
||||||
Topic = emqx_topic:systop(lists:concat(['sysmon/', Event])),
|
Topic = emqx_topic:systop(lists:concat(['sysmon/', Event])),
|
||||||
|
|
|
@ -35,6 +35,11 @@
|
||||||
{self(), busy_port,
|
{self(), busy_port,
|
||||||
fmt("busy_port warning: suspid = ~p, port = ~p",
|
fmt("busy_port warning: suspid = ~p, port = ~p",
|
||||||
[self(), ?FAKE_PORT]), ?FAKE_PORT},
|
[self(), ?FAKE_PORT]), ?FAKE_PORT},
|
||||||
|
%% for the case when the port is missing, for some
|
||||||
|
%% reason.
|
||||||
|
{self(), busy_port,
|
||||||
|
fmt("busy_port warning: suspid = ~p, port = ~p",
|
||||||
|
[self(), []]), []},
|
||||||
{self(), busy_dist_port,
|
{self(), busy_dist_port,
|
||||||
fmt("busy_dist_port warning: suspid = ~p, port = ~p",
|
fmt("busy_dist_port warning: suspid = ~p, port = ~p",
|
||||||
[self(), ?FAKE_PORT]), ?FAKE_PORT},
|
[self(), ?FAKE_PORT]), ?FAKE_PORT},
|
||||||
|
@ -120,6 +125,16 @@ t_sys_mon(_Config) ->
|
||||||
validate_sys_mon_info(PidOrPort, SysMonName, ValidateInfo, InfoOrPort)
|
validate_sys_mon_info(PidOrPort, SysMonName, ValidateInfo, InfoOrPort)
|
||||||
end, ?INPUTINFO).
|
end, ?INPUTINFO).
|
||||||
|
|
||||||
|
%% Existing port, but closed.
|
||||||
|
t_sys_mon_dead_port(_Config) ->
|
||||||
|
process_flag(trap_exit, true),
|
||||||
|
Port = dead_port(),
|
||||||
|
{PidOrPort, SysMonName, ValidateInfo, InfoOrPort} =
|
||||||
|
{self(), busy_port,
|
||||||
|
fmt("busy_port warning: suspid = ~p, port = ~p",
|
||||||
|
[self(), Port]), Port},
|
||||||
|
validate_sys_mon_info(PidOrPort, SysMonName, ValidateInfo, InfoOrPort).
|
||||||
|
|
||||||
t_sys_mon2(_Config) ->
|
t_sys_mon2(_Config) ->
|
||||||
?SYSMON ! {timeout, ignored, reset},
|
?SYSMON ! {timeout, ignored, reset},
|
||||||
?SYSMON ! {ignored},
|
?SYSMON ! {ignored},
|
||||||
|
@ -151,3 +166,8 @@ some_function(Parent, _Arg2) ->
|
||||||
stop ->
|
stop ->
|
||||||
ok
|
ok
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
dead_port() ->
|
||||||
|
Port = erlang:open_port({spawn, "ls"}, []),
|
||||||
|
exit(Port, kill),
|
||||||
|
Port.
|
||||||
|
|
Loading…
Reference in New Issue