Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore the expired messages #3083

Merged
merged 1 commit into from Dec 7, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 14 additions & 9 deletions src/emqx_session.erl
Expand Up @@ -400,9 +400,16 @@ dequeue(Cnt, Msgs, Q) ->
case emqx_mqueue:out(Q) of
{empty, _Q} -> dequeue(0, Msgs, Q);
{{value, Msg = #message{qos = ?QOS_0}}, Q1} ->
dequeue(Cnt, [Msg|Msgs], Q1);
dequeue(Cnt, acc_msg(Msg, Msgs), Q1);
{{value, Msg}, Q1} ->
dequeue(Cnt-1, [Msg|Msgs], Q1)
dequeue(Cnt-1, acc_msg(Msg, Msgs), Q1)
end.

-compile({inline, [acc_msg/2]}).
acc_msg(Msg, Msgs) ->
case emqx_message:is_expired(Msg) of
true -> Msgs;
false -> [Msg|Msgs]
end.

%%--------------------------------------------------------------------
Expand Down Expand Up @@ -590,19 +597,17 @@ resume(ClientId, #session{subscriptions = Subs}) ->

-spec(redeliver(session()) -> {ok, replies(), session()}).
redeliver(Session = #session{inflight = Inflight}) ->
Pubs = replay(Inflight),
Pubs = lists:map(fun to_pub/1, emqx_inflight:to_list(Inflight)),
case dequeue(Session) of
{ok, NSession} -> {ok, Pubs, NSession};
{ok, More, NSession} ->
{ok, lists:append(Pubs, More), NSession}
end.

replay(Inflight) ->
lists:map(fun({PacketId, {pubrel, _Ts}}) ->
{pubrel, PacketId};
({PacketId, {Msg, _Ts}}) ->
{PacketId, emqx_message:set_flag(dup, true, Msg)}
end, emqx_inflight:to_list(Inflight)).
to_pub({PacketId, {pubrel, _Ts}}) ->
{pubrel, PacketId};
to_pub({PacketId, {Msg, _Ts}}) ->
{PacketId, emqx_message:set_flag(dup, true, Msg)}.

%%--------------------------------------------------------------------
%% Next Packet Id
Expand Down