From 84e1e29c7fed92b11746e6aa7c080b110c13528c Mon Sep 17 00:00:00 2001 From: anlicheng <244108715@qq.com> Date: Mon, 27 Apr 2026 15:37:58 +0800 Subject: [PATCH] fix --- src/transport/tcp/ssl_channel.erl | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/transport/tcp/ssl_channel.erl b/src/transport/tcp/ssl_channel.erl index 87239e3..2168ede 100644 --- a/src/transport/tcp/ssl_channel.erl +++ b/src/transport/tcp/ssl_channel.erl @@ -109,10 +109,11 @@ handle_cast({command, Command}, State = #state{transport = Transport, socket = S %% 推送需要响应的请求 handle_cast({request_call, ReceiverPid, Ref, Body}, State = #state{transport = Transport, socket = Socket, inflight = Inflight}) -> Packet = term_to_binary({request, Ref, Body}), - TimerRef = erlang:start_timer(?INFLIGHT_TIMEOUT, self(), {request_timeout, Ref}), Transport:send(Socket, Packet), + TimerRef = erlang:start_timer(?INFLIGHT_TIMEOUT, self(), {request_timeout, Ref}), RequestInfo = #inflight_request{receiver_pid = ReceiverPid, timer_ref = TimerRef}, + {noreply, State#state{inflight = maps:put(Ref, RequestInfo, Inflight)}}. handle_info({timeout, TimerRef, {request_timeout, Ref}}, State = #state{inflight = Inflight}) -> @@ -133,21 +134,20 @@ handle_info({'DOWN', _, process, HostPid, Reason}, State = #state{uuid = UUID, h logger:debug("[ws_channel] uuid: ~p, channel will close because host exited with reason: ~p", [UUID, Reason]), {stop, Reason, State}; -handle_info({ssl, Socket, PacketBin}, State = #state{transport = Transport, socket = Socket, host_pid = HostPid, inflight = Inflight}) - when is_binary(PacketBin) -> - case catch binary_to_term(PacketBin, [safe]) of +handle_info({ssl, Socket, PacketBin}, State = #state{transport = Transport, socket = Socket, host_pid = HostPid, inflight = Inflight}) when is_binary(PacketBin) -> + try binary_to_term(PacketBin, [safe]) of {request, Ref, Body} -> handle_request_frame(Ref, Body, Transport, Socket, State); {message, Body} -> handle_message_frame(Body, HostPid, State); {response, Ref, Response} -> handle_response_frame(Ref, Response, Inflight, State); - {'EXIT', Reason} -> - logger:warning("[ssl_channel] invalid packet: ~p", [Reason]), - {stop, bad_packet, State}; Other -> logger:warning("[ssl_channel] unsupported packet: ~p", [Other]), {stop, bad_packet, State} + catch error:Error -> + logger:warning("[ssl_channel] binary_to_term get error: ~p", [Error]), + {stop, bad_packet, State} end; handle_info({ssl_closed, Socket}, State = #state{socket = Socket}) -> @@ -179,8 +179,7 @@ code_change(_OldVsn, State, _Extra) -> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -spec handle_request_frame(reference(), tuple(), module(), any(), #state{}) -> {noreply, #state{}} | {stop, term(), #state{}}. -handle_request_frame(Ref, - {auth_request, #{uuid := UUID, token := Token, timestamp := Timestamp}}, +handle_request_frame(Ref, {auth_request, #{uuid := UUID, token := Token, timestamp := Timestamp}}, Transport, Socket, State) -> logger:debug("[ws_channel] auth uuid: ~p", [UUID]),