EMQX failed to start when the listening port was occupied (#3354)

This commit is contained in:
张奇怪 2020-04-11 10:18:35 +08:00 committed by GitHub
parent d49f4118fe
commit 9ba938b9d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 8 deletions

View File

@ -44,17 +44,16 @@
start() ->
lists:foreach(fun start_listener/1, emqx:get_env(listeners, [])).
-spec(start_listener(listener()) -> {ok, pid()} | {error, term()}).
-spec(start_listener(listener()) -> ok).
start_listener({Proto, ListenOn, Options}) ->
StartRet = start_listener(Proto, ListenOn, Options),
case StartRet of
case start_listener(Proto, ListenOn, Options) of
{ok, _} -> io:format("Start mqtt:~s listener on ~s successfully.~n",
[Proto, format(ListenOn)]);
{error, Reason} ->
io:format(standard_error, "Failed to start mqtt:~s listener on ~s - ~0p~n!",
[Proto, format(ListenOn), Reason])
end,
StartRet.
[Proto, format(ListenOn), Reason]),
error(Reason)
end.
%% Start MQTT/TCP listener
-spec(start_listener(esockd:proto(), esockd:listen_on(), [esockd:option()])

View File

@ -21,6 +21,7 @@
-include("emqx.hrl").
-include("emqx_mqtt.hrl").
-include_lib("eunit/include/eunit.hrl").
all() -> emqx_ct:all(?MODULE).
@ -37,7 +38,7 @@ end_per_suite(_Config) ->
t_start_stop_listeners(_) ->
ok = emqx_listeners:start(),
{error, _} = emqx_listeners:start_listener({ws,{"127.0.0.1", 8083}, []}),
?assertException(error, _, emqx_listeners:start_listener({ws,{"127.0.0.1", 8083}, []})),
ok = emqx_listeners:stop().
t_restart_listeners(_) ->
@ -90,4 +91,4 @@ get_base_dir(Module) ->
get_base_dir() ->
get_base_dir(?MODULE).