diff --git a/apps/iot/src/websocket/ws_channel.erl b/apps/iot/src/websocket/ws_channel.erl index 65c5e3f..c2f4fd8 100644 --- a/apps/iot/src/websocket/ws_channel.erl +++ b/apps/iot/src/websocket/ws_channel.erl @@ -136,7 +136,7 @@ websocket_handle({binary, <> error -> lager:warning("[ws_channel] get unknown publish response message: ~p, packet_id: ~p", [Body, PacketId]), {ok, State}; - {{ReceiverPid, Ref}, NInflight} -> + {{ReceiverPid, Ref, _}, NInflight} -> case is_pid(ReceiverPid) andalso is_process_alive(ReceiverPid) of true when Body == <<>> -> ReceiverPid ! {ws_response, Ref}; @@ -164,7 +164,7 @@ websocket_info({publish, ReceiverPid, Ref, Msg, Timeout}, State = #state{packet_ TTL = iot_util:timestamp() + Timeout, maps:put(PacketId, {ReceiverPid, Ref, TTL}, Inflight); false -> - maps:put(PacketId, {ReceiverPid, Ref}, Inflight) + maps:put(PacketId, {ReceiverPid, Ref, 0}, Inflight) end, {reply, {binary, <>}, State#state{packet_id = PacketId + 1, inflight = NInflight}}; @@ -177,13 +177,8 @@ websocket_info({timeout, _, clean_ticker}, State=#state{inflight = Inflight}) -> clean_ticker(), Timestamp = iot_util:timestamp(), - NInflight = maps:filter(fun(_, Promise) -> - case Promise of - {_ReceiverPid, _Ref, TTL} -> - TTL < Timestamp; - {_ReceiverPid, _Ref} -> - true - end + NInflight = maps:filter(fun(_, {_ReceiverPid, _Ref, TTL}) -> + TTL == 0 orelse (TTL > 0 andalso TTL < Timestamp) end, Inflight), {ok, State#state{inflight = NInflight}};