fix(ws): fix MQTT packets may be reversed in the WS

Fix when a WS packet contains many MQTT packets, the order of MQTT packets will be reversed
This commit is contained in:
firest 2023-07-11 18:40:06 +08:00
parent a7d7cd6414
commit 211486a946
2 changed files with 9 additions and 1 deletions

View File

@ -699,7 +699,7 @@ check_oom(State = #state{channel = Channel}) ->
%%--------------------------------------------------------------------
parse_incoming(<<>>, Packets, State) ->
{Packets, State};
{lists:reverse(Packets), State};
parse_incoming(Data, Packets, State = #state{parse_state = ParseState}) ->
try emqx_frame:parse(Data, ParseState) of
{more, NParseState} ->

View File

@ -530,6 +530,14 @@ t_parse_incoming(_) ->
Packet = ?PUBLISH_PACKET(?QOS_0, <<"t">>, undefined, <<>>),
?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(_) ->
{Packets, _St} = ?ws_conn:parse_incoming(<<3, 2, 1, 0>>, [], st()),
FrameError = {frame_error, malformed_packet},