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:
lafirest 2023-07-11 20:09:55 +08:00 committed by GitHub
commit 903d81b532
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 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},

View File

@ -0,0 +1,2 @@
Fix while a WebSocket packet contains more than one MQTT packet, the order of MQTT packets will be reversed.