Pārlūkot izejas kodu

fix: disconnect the client due to exceed receive-maximum packets

As described in the 5.0 specification, we should disconnect clients that
exceed the receive-maximum limit.

> If it receives more than Receive Maximum QoS 1 and QoS 2 PUBLISH packets
where it has not sent a PUBACK or PUBCOMP in response, **the Server uses a
DISCONNECT packet with Reason Code 0x9**

fix: #6447
JianBo He 4 gadi atpakaļ
vecāks
revīzija
cb8a3725b4
2 mainītis faili ar 3 papildinājumiem un 2 dzēšanām
  1. 1 1
      src/emqx_channel.erl
  2. 2 1
      test/emqx_channel_SUITE.erl

+ 1 - 1
src/emqx_channel.erl

@@ -599,7 +599,7 @@ do_publish(PacketId, Msg = #message{qos = ?QOS_2},
             ?LOG(warning, "Dropped the qos2 packet ~w "
             ?LOG(warning, "Dropped the qos2 packet ~w "
                  "due to awaiting_rel is full.", [PacketId]),
                  "due to awaiting_rel is full.", [PacketId]),
             ok = emqx_metrics:inc('packets.publish.dropped'),
             ok = emqx_metrics:inc('packets.publish.dropped'),
-            handle_out(pubrec, {PacketId, RC}, Channel)
+            handle_out(disconnect, RC, Channel)
     end.
     end.
 
 
 ensure_quota(_, Channel = #channel{quota = undefined}) ->
 ensure_quota(_, Channel = #channel{quota = undefined}) ->

+ 2 - 1
test/emqx_channel_SUITE.erl

@@ -209,7 +209,8 @@ t_handle_in_qos2_publish_with_error_return(_) ->
     {ok, ?PUBREC_PACKET(2, ?RC_NO_MATCHING_SUBSCRIBERS), Channel1} =
     {ok, ?PUBREC_PACKET(2, ?RC_NO_MATCHING_SUBSCRIBERS), Channel1} =
         emqx_channel:handle_in(Publish2, Channel),
         emqx_channel:handle_in(Publish2, Channel),
     Publish3 = ?PUBLISH_PACKET(?QOS_2, <<"topic">>, 3, <<"payload">>),
     Publish3 = ?PUBLISH_PACKET(?QOS_2, <<"topic">>, 3, <<"payload">>),
-    {ok, ?PUBREC_PACKET(3, ?RC_RECEIVE_MAXIMUM_EXCEEDED), Channel1} =
+    {ok, [{outgoing, ?DISCONNECT_PACKET(?RC_RECEIVE_MAXIMUM_EXCEEDED)},
+          {close, receive_maximum_exceeded}], Channel1} =
         emqx_channel:handle_in(Publish3, Channel1).
         emqx_channel:handle_in(Publish3, Channel1).
 
 
 t_handle_in_puback_ok(_) ->
 t_handle_in_puback_ok(_) ->