Просмотр исходного кода

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
Gilbert 6 лет назад
Родитель
Сommit
475cabde4d
2 измененных файлов с 18 добавлено и 1 удалено
  1. 5 1
      src/emqx_ws_channel.erl
  2. 13 0
      test/emqx_ws_channel_SUITE.erl

+ 5 - 1
src/emqx_ws_channel.erl

@@ -221,7 +221,11 @@ websocket_handle(Frame, State)
     {ok, ensure_stats_timer(State)};
 websocket_handle({FrameType, _}, State)
   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) ->
     gen_server:reply(From, info(State)),

+ 13 - 0
test/emqx_ws_channel_SUITE.erl

@@ -31,6 +31,7 @@
 all() ->
     [ t_ws_connect_api
     , t_ws_auth_failure
+    , t_ws_other_type_frame
     ].
 
 init_per_suite(Config) ->
@@ -71,6 +72,18 @@ t_ws_connect_api(_Config) ->
     {close, _} = rfc6455_client:close(WS),
     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) ->
     emqx_frame:serialize(Packet).