Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:Ledest:erlang:26
erlang
3037-Fix-bug-in-continuation-of-incomolete-pack...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 3037-Fix-bug-in-continuation-of-incomolete-packet-that-ca.patch of Package erlang
From c6550fbc82ecfbffb9ac1dcb38b55a7e62e45aa1 Mon Sep 17 00:00:00 2001 From: Raimo Niskanen <raimo@erlang.org> Date: Thu, 22 Feb 2024 19:26:10 +0100 Subject: [PATCH 07/22] Fix bug in continuation of incomolete packet that caused hanging read --- lib/kernel/src/gen_tcp_socket.erl | 82 +++++++++++++++++++------------ 1 file changed, 51 insertions(+), 31 deletions(-) diff --git a/lib/kernel/src/gen_tcp_socket.erl b/lib/kernel/src/gen_tcp_socket.erl index a4c859ed74..daf0c5d823 100644 --- a/lib/kernel/src/gen_tcp_socket.erl +++ b/lib/kernel/src/gen_tcp_socket.erl @@ -2346,44 +2346,46 @@ handle_recv_more(P, #{buffer := Buffer} = D, Length, ActionsR) -> end) of {ok, <<Data/binary>>} -> + %% ?DBG({socket_recv, Length, byte_size(Data)}), handle_recv(P, D#{buffer := [Data | Buffer]}, ActionsR); {select, {?select_info(_) = SelectInfo, <<Data/binary>>}} -> - %% ?DBG([{select_info, SelectInfo}]), + %% ?DBG({socket_recv, Length, + %% {select_info, SelectInfo, byte_size(Data)}}), {next_state, #recv{info = SelectInfo}, {P, D#{buffer := [Data | Buffer]}}, reverse(ActionsR)}; {select, ?select_info(_) = SelectInfo} -> - %% ?DBG([{select_info, SelectInfo}]), + %% ?DBG({socket_recv, Length, {select_info, SelectInfo}}), {next_state, #recv{info = SelectInfo}, {P, D}, reverse(ActionsR)}; {completion, ?completion_info(_) = CompletionInfo} -> - %% ?DBG([{completion_info, CompletionInfo}]), + %% ?DBG({socket_recv, Length, {completion_info, CompletionInfo}}), {next_state, #recv{info = CompletionInfo}, {P, D}, reverse(ActionsR)}; {error, {Reason, <<Data/binary>>}} -> + %% ?DBG({socket_recv, Length, {error, Reason, byte_size(Data)}}), handle_recv_error_packet( P, D#{buffer := [Data | Buffer]}, ActionsR, Reason); {error, Reason} -> - %% ?DBG({P#params.socket, error, Reason}), + %% ?DBG({socket_recv, Length, {error, Reason}}), handle_recv_error(P, D, ActionsR, Reason) end. handle_recv_packet(P, D, ActionsR) -> + %% ?DBG({}), case decode_packet(D) of - {ok, Decoded, Rest} -> - handle_recv_deliver(P, D#{buffer := Rest}, ActionsR, Decoded); - {more, undefined} -> - handle_recv_more(P, D, 0, ActionsR); - {more, Length} -> - handle_recv_more(P, D, Length, ActionsR); - {error, Reason} -> + {D_1, ok, Decoded} -> + handle_recv_deliver(P, D_1, ActionsR, Decoded); + {D_1, more, Missing} -> + handle_recv_more(P, D_1, Missing, ActionsR); + {D_1, error, Reason} -> handle_recv_error( - P, D, ActionsR, + P, D_1, ActionsR, case Reason of invalid -> emsgsize; _ -> Reason @@ -2392,24 +2394,22 @@ handle_recv_packet(P, D, ActionsR) -> handle_recv_error_packet(P, D, ActionsR, Reason) -> case decode_packet(D) of - {ok, Decoded, Rest} -> + {D_1, ok, Decoded} -> handle_recv_error( - P, recv_data_deliver(P, D#{buffer := Rest}, ActionsR, Decoded), + P, recv_data_deliver(P, D_1, ActionsR, Decoded), Reason); - {more, _} -> - handle_recv_error(P, D, ActionsR, Reason); - {error, _} -> - handle_recv_error(P, D, ActionsR, Reason) + {D_1, _, _} -> + handle_recv_error(P, D_1, ActionsR, Reason) end. decode_packet( #{packet := (PacketType = line), line_delimiter := LineDelimiter, packet_size := PacketSize, - buffer := Buffer}) -> + buffer := Buffer} = D) -> %% decode_packet( - PacketType, Buffer, + D, PacketType, Buffer, [{packet_size, PacketSize}, {line_delimiter, LineDelimiter}, {line_length, PacketSize}]); @@ -2417,26 +2417,47 @@ decode_packet( #{packet := http, recv_httph := true, packet_size := PacketSize, - buffer := Buffer}) -> + buffer := Buffer} = D) -> %% - decode_packet(httph, Buffer, [{packet_size, PacketSize}]); + decode_packet(D, httph, Buffer, [{packet_size, PacketSize}]); decode_packet( #{packet := http_bin, recv_httph := true, packet_size := PacketSize, - buffer := Buffer}) -> + buffer := Buffer} = D) -> %% - decode_packet(httph_bin, Buffer, [{packet_size, PacketSize}]); + decode_packet(D, httph_bin, Buffer, [{packet_size, PacketSize}]); decode_packet( #{packet := PacketType, packet_size := PacketSize, - buffer := Buffer}) -> + buffer := Buffer} = D) -> %% - decode_packet(PacketType, Buffer, [{packet_size, PacketSize}]). - -decode_packet(PacketType, Buffer, Options) -> - erlang:decode_packet(PacketType, condense_buffer(Buffer), Options). - + decode_packet(D, PacketType, Buffer, [{packet_size, PacketSize}]). +%% +decode_packet(D, PacketType, Buffer, Options) -> + CondensedBuffer = condense_buffer(Buffer), + case + erlang:decode_packet(PacketType, CondensedBuffer, Options) + of + {ok, Decoded, Rest} -> + {D#{buffer := Rest}, ok, Decoded}; + Other when is_binary(Buffer) -> + %% ?DBG({decode_packet, byte_size(CondensedBuffer), Other}), + decode_packet(D, Other); + Other when is_list(Buffer) -> + %% ?DBG({decode_packet, byte_size(CondensedBuffer), Other}), + decode_packet(D#{buffer := CondensedBuffer}, Other) + end. +%% +decode_packet(D, Other) -> + case Other of + {more, undefined} -> + {D, more, 0}; + {more, Length} -> + {D, more, Length - byte_size(maps:get(buffer, D))}; + {error, Reason} -> + {D, error, Reason} + end. handle_recv_deliver(P, D, ActionsR, Data) -> handle_connected(P, recv_data_deliver(P, D, ActionsR, Data)). @@ -2542,7 +2563,6 @@ recv_data_deliver( {recv_stop(next_packet(D_1, Packet, Data)), ActionsR}; #{active := Active} -> - %% ?DBG({active, Active}), ModuleSocket = module_socket(P), Owner ! case Deliver of -- 2.35.3
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor