Merge pull request #11250 from lafirest/fix/ws_order
fix(ws): fix MQTT packets may be reversed in the WS
This commit is contained in:
commit
903d81b532
|
@ -699,7 +699,7 @@ check_oom(State = #state{channel = Channel}) ->
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
|
||||||
parse_incoming(<<>>, Packets, State) ->
|
parse_incoming(<<>>, Packets, State) ->
|
||||||
{Packets, State};
|
{lists:reverse(Packets), State};
|
||||||
parse_incoming(Data, Packets, State = #state{parse_state = ParseState}) ->
|
parse_incoming(Data, Packets, State = #state{parse_state = ParseState}) ->
|
||||||
try emqx_frame:parse(Data, ParseState) of
|
try emqx_frame:parse(Data, ParseState) of
|
||||||
{more, NParseState} ->
|
{more, NParseState} ->
|
||||||
|
|
|
@ -530,6 +530,14 @@ t_parse_incoming(_) ->
|
||||||
Packet = ?PUBLISH_PACKET(?QOS_0, <<"t">>, undefined, <<>>),
|
Packet = ?PUBLISH_PACKET(?QOS_0, <<"t">>, undefined, <<>>),
|
||||||
?assertMatch([{incoming, Packet}], Packets1).
|
?assertMatch([{incoming, Packet}], Packets1).
|
||||||
|
|
||||||
|
t_parse_incoming_order(_) ->
|
||||||
|
Packet1 = ?PUBLISH_PACKET(?QOS_0, <<"t1">>, undefined, <<>>),
|
||||||
|
Packet2 = ?PUBLISH_PACKET(?QOS_0, <<"t2">>, undefined, <<>>),
|
||||||
|
Bin1 = emqx_frame:serialize(Packet1),
|
||||||
|
Bin2 = emqx_frame:serialize(Packet2),
|
||||||
|
{Packets1, _} = ?ws_conn:parse_incoming(erlang:iolist_to_binary([Bin1, Bin2]), [], st()),
|
||||||
|
?assertMatch([{incoming, Packet1}, {incoming, Packet2}], Packets1).
|
||||||
|
|
||||||
t_parse_incoming_frame_error(_) ->
|
t_parse_incoming_frame_error(_) ->
|
||||||
{Packets, _St} = ?ws_conn:parse_incoming(<<3, 2, 1, 0>>, [], st()),
|
{Packets, _St} = ?ws_conn:parse_incoming(<<3, 2, 1, 0>>, [], st()),
|
||||||
FrameError = {frame_error, malformed_packet},
|
FrameError = {frame_error, malformed_packet},
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
Fix while a WebSocket packet contains more than one MQTT packet, the order of MQTT packets will be reversed.
|
||||||
|
|
Loading…
Reference in New Issue