Merge pull request #8650 from qzhuyan/fix/william/keep-alive-check

fix: keep alive check
This commit is contained in:
William Yang 2022-08-09 11:37:12 +02:00 committed by GitHub
commit 30f24131e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 13 deletions

View File

@ -708,8 +708,6 @@ handle_timeout(
TRef, TRef,
keepalive, keepalive,
State = #state{ State = #state{
transport = Transport,
socket = Socket,
channel = Channel channel = Channel
} }
) -> ) ->
@ -717,12 +715,9 @@ handle_timeout(
disconnected -> disconnected ->
{ok, State}; {ok, State};
_ -> _ ->
case Transport:getstat(Socket, [recv_oct]) of %% recv_pkt: valid MQTT message
{ok, [{recv_oct, RecvOct}]} -> RecvCnt = emqx_pd:get_counter(recv_pkt),
handle_timeout(TRef, {keepalive, RecvOct}, State); handle_timeout(TRef, {keepalive, RecvCnt}, State)
{error, Reason} ->
handle_info({sock_error, Reason}, State)
end
end; end;
handle_timeout(TRef, Msg, State) -> handle_timeout(TRef, Msg, State) ->
with_channel(handle_timeout, [TRef, Msg], State). with_channel(handle_timeout, [TRef, Msg], State).

View File

@ -316,11 +316,6 @@ t_handle_timeout(_) ->
emqx_connection:handle_timeout(TRef, keepalive, State) emqx_connection:handle_timeout(TRef, keepalive, State)
), ),
ok = meck:expect(emqx_transport, getstat, fun(_Sock, _Options) -> {error, for_testing} end),
?assertMatch(
{stop, {shutdown, for_testing}, _NState},
emqx_connection:handle_timeout(TRef, keepalive, State)
),
?assertMatch({ok, _NState}, emqx_connection:handle_timeout(TRef, undefined, State)). ?assertMatch({ok, _NState}, emqx_connection:handle_timeout(TRef, undefined, State)).
t_parse_incoming(_) -> t_parse_incoming(_) ->