fix: set a timeout for tcp connect

This commit is contained in:
Stefan Strigler 2022-12-21 15:20:53 +01:00
parent 96ca0d9f49
commit c42c99f94f
1 changed files with 2 additions and 1 deletions

View File

@ -512,11 +512,12 @@ host_and_port(webhook, #{<<"url">> := Url}) ->
host_and_port(_Unknown, _) ->
undefined.
%% [TODO] remove in EMQX-8588 when resource manager handles things more elegantly
test_connection(undefined) ->
%% be friendly, it might fail later on with a 'timeout' error.
ok;
test_connection({Host, Port}) ->
case gen_tcp:connect(Host, Port, []) of
case gen_tcp:connect(Host, Port, [], 5000) of
{ok, TestSocket} -> gen_tcp:close(TestSocket);
Error -> Error
end.