Skip to content

Commit 9ba938b

Browse files
authored
EMQX failed to start when the listening port was occupied (emqx#3354)
1 parent d49f411 commit 9ba938b

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/emqx_listeners.erl

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,16 @@
4444
start() ->
4545
lists:foreach(fun start_listener/1, emqx:get_env(listeners, [])).
4646

47-
-spec(start_listener(listener()) -> {ok, pid()} | {error, term()}).
47+
-spec(start_listener(listener()) -> ok).
4848
start_listener({Proto, ListenOn, Options}) ->
49-
StartRet = start_listener(Proto, ListenOn, Options),
50-
case StartRet of
49+
case start_listener(Proto, ListenOn, Options) of
5150
{ok, _} -> io:format("Start mqtt:~s listener on ~s successfully.~n",
5251
[Proto, format(ListenOn)]);
5352
{error, Reason} ->
5453
io:format(standard_error, "Failed to start mqtt:~s listener on ~s - ~0p~n!",
55-
[Proto, format(ListenOn), Reason])
56-
end,
57-
StartRet.
54+
[Proto, format(ListenOn), Reason]),
55+
error(Reason)
56+
end.
5857

5958
%% Start MQTT/TCP listener
6059
-spec(start_listener(esockd:proto(), esockd:listen_on(), [esockd:option()])

test/emqx_listeners_SUITE.erl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
-include("emqx.hrl").
2323
-include("emqx_mqtt.hrl").
24+
-include_lib("eunit/include/eunit.hrl").
2425

2526
all() -> emqx_ct:all(?MODULE).
2627

@@ -37,7 +38,7 @@ end_per_suite(_Config) ->
3738

3839
t_start_stop_listeners(_) ->
3940
ok = emqx_listeners:start(),
40-
{error, _} = emqx_listeners:start_listener({ws,{"127.0.0.1", 8083}, []}),
41+
?assertException(error, _, emqx_listeners:start_listener({ws,{"127.0.0.1", 8083}, []})),
4142
ok = emqx_listeners:stop().
4243

4344
t_restart_listeners(_) ->
@@ -90,4 +91,4 @@ get_base_dir(Module) ->
9091

9192
get_base_dir() ->
9293
get_base_dir(?MODULE).
93-
94+

0 commit comments

Comments
 (0)