From 0b116bc208096b03686284f12e59d584c0342317 Mon Sep 17 00:00:00 2001 From: tradingtrace Date: Sun, 23 Jun 2019 11:20:22 +0800 Subject: [PATCH] Fix the massages order when batch dispatching --- src/emqx_session.erl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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) ->