Fix issue#2619 (#2646)

* Fix issue#2619
Prior to this change, websocket connection would not be disconnected
when dataframe type is other frametype. However, in mqtt spec, it
shoud be disconnected.

This change fix this inconsistent behaviour with mqtt 5.0
This commit is contained in:
Gilbert 2019-06-21 21:21:49 +08:00 committed by turtleDeng
parent 20188f9189
commit 475cabde4d
2 changed files with 18 additions and 1 deletions

View File

@ -221,7 +221,11 @@ websocket_handle(Frame, State)
{ok, ensure_stats_timer(State)}; {ok, ensure_stats_timer(State)};
websocket_handle({FrameType, _}, State) websocket_handle({FrameType, _}, State)
when FrameType =:= ping; FrameType =:= pong -> when FrameType =:= ping; FrameType =:= pong ->
{ok, ensure_stats_timer(State)}. {ok, ensure_stats_timer(State)};
%% According to mqtt spec[https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901285]
websocket_handle({_OtherFrameType, _}, State) ->
?LOG(error, "Frame error: Other type of data frame"),
shutdown(other_frame_type, State).
websocket_info({call, From, info}, State) -> websocket_info({call, From, info}, State) ->
gen_server:reply(From, info(State)), gen_server:reply(From, info(State)),

View File

@ -31,6 +31,7 @@
all() -> all() ->
[ t_ws_connect_api [ t_ws_connect_api
, t_ws_auth_failure , t_ws_auth_failure
, t_ws_other_type_frame
]. ].
init_per_suite(Config) -> init_per_suite(Config) ->
@ -71,6 +72,18 @@ t_ws_connect_api(_Config) ->
{close, _} = rfc6455_client:close(WS), {close, _} = rfc6455_client:close(WS),
ok. ok.
t_ws_other_type_frame(_Config) ->
WS = rfc6455_client:new("ws://127.0.0.1:8083" ++ "/mqtt", self()),
{ok, _} = rfc6455_client:open(WS),
ok = rfc6455_client:send_binary(WS, raw_send_serialize(?CLIENT)),
{binary, Bin} = rfc6455_client:recv(WS),
Connack = ?CONNACK_PACKET(?CONNACK_ACCEPT),
{ok, Connack, <<>>, _} = raw_recv_pase(Bin),
rfc6455_client:send(WS, <<"testdata">>),
timer:sleep(1000),
?assertEqual(undefined, erlang:process_info(WS)),
ok.
raw_send_serialize(Packet) -> raw_send_serialize(Packet) ->
emqx_frame:serialize(Packet). emqx_frame:serialize(Packet).