EMQX failed to start when the listening port was occupied (#3354)
This commit is contained in:
parent
d49f4118fe
commit
9ba938b9d9
|
@ -44,17 +44,16 @@
|
||||||
start() ->
|
start() ->
|
||||||
lists:foreach(fun start_listener/1, emqx:get_env(listeners, [])).
|
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}) ->
|
start_listener({Proto, ListenOn, Options}) ->
|
||||||
StartRet = start_listener(Proto, ListenOn, Options),
|
case start_listener(Proto, ListenOn, Options) of
|
||||||
case StartRet of
|
|
||||||
{ok, _} -> io:format("Start mqtt:~s listener on ~s successfully.~n",
|
{ok, _} -> io:format("Start mqtt:~s listener on ~s successfully.~n",
|
||||||
[Proto, format(ListenOn)]);
|
[Proto, format(ListenOn)]);
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
io:format(standard_error, "Failed to start mqtt:~s listener on ~s - ~0p~n!",
|
io:format(standard_error, "Failed to start mqtt:~s listener on ~s - ~0p~n!",
|
||||||
[Proto, format(ListenOn), Reason])
|
[Proto, format(ListenOn), Reason]),
|
||||||
end,
|
error(Reason)
|
||||||
StartRet.
|
end.
|
||||||
|
|
||||||
%% Start MQTT/TCP listener
|
%% Start MQTT/TCP listener
|
||||||
-spec(start_listener(esockd:proto(), esockd:listen_on(), [esockd:option()])
|
-spec(start_listener(esockd:proto(), esockd:listen_on(), [esockd:option()])
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
|
|
||||||
-include("emqx.hrl").
|
-include("emqx.hrl").
|
||||||
-include("emqx_mqtt.hrl").
|
-include("emqx_mqtt.hrl").
|
||||||
|
-include_lib("eunit/include/eunit.hrl").
|
||||||
|
|
||||||
all() -> emqx_ct:all(?MODULE).
|
all() -> emqx_ct:all(?MODULE).
|
||||||
|
|
||||||
|
@ -37,7 +38,7 @@ end_per_suite(_Config) ->
|
||||||
|
|
||||||
t_start_stop_listeners(_) ->
|
t_start_stop_listeners(_) ->
|
||||||
ok = emqx_listeners:start(),
|
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().
|
ok = emqx_listeners:stop().
|
||||||
|
|
||||||
t_restart_listeners(_) ->
|
t_restart_listeners(_) ->
|
||||||
|
@ -90,4 +91,4 @@ get_base_dir(Module) ->
|
||||||
|
|
||||||
get_base_dir() ->
|
get_base_dir() ->
|
||||||
get_base_dir(?MODULE).
|
get_base_dir(?MODULE).
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue