diff --git a/src/emqx_session.erl b/src/emqx_session.erl index 49454d8ac..7d8722c68 100644 --- a/src/emqx_session.erl +++ b/src/emqx_session.erl @@ -798,7 +798,7 @@ handle_dispatch(Msgs, State = #state{inflight = Inflight, subscriptions = SubMap}) -> SessProps = #{client_id => ClientId, username => Username}, %% Drain the mailbox and batch deliver - Msgs1 = drain_m(batch_n(Inflight), Msgs), + Msgs1 = Msgs ++ drain_m(batch_n(Inflight)), %% Ack the messages for shared subscription Msgs2 = maybe_ack_shared(Msgs1, State), %% Process suboptions @@ -821,6 +821,9 @@ batch_n(Inflight) -> Sz -> Sz - emqx_inflight:size(Inflight) end. +drain_m(Cnt) -> + drain_m(Cnt, []). + drain_m(Cnt, Msgs) when Cnt =< 0 -> lists:reverse(Msgs); drain_m(Cnt, Msgs) ->