Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:Ledest:erlang:24
erlang
4454-Clean-up-problems-with-socket-shutdown-and...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 4454-Clean-up-problems-with-socket-shutdown-and-rotted-be.patch of Package erlang
From 055490e75134cedc5c1ae0a7d461a9722c57c1ac Mon Sep 17 00:00:00 2001 From: Raimo Niskanen <raimo@erlang.org> Date: Mon, 26 Sep 2022 17:23:59 +0200 Subject: [PATCH 04/27] Clean up problems with socket shutdown and rotted benchmark --- lib/ssl/src/ssl_gen_statem.erl | 22 ++++++++++++-- lib/ssl/src/tls_sender.erl | 28 +++++++++-------- lib/ssl/test/inet_crypto_dist.erl | 32 +++++++++++--------- lib/ssl/test/ssl_dist_bench_SUITE.erl | 43 ++++++++++++++++++++++++++- 4 files changed, 95 insertions(+), 30 deletions(-) diff --git a/lib/ssl/src/ssl_gen_statem.erl b/lib/ssl/src/ssl_gen_statem.erl index 0b4d032f78..2f59b150ca 100644 --- a/lib/ssl/src/ssl_gen_statem.erl +++ b/lib/ssl/src/ssl_gen_statem.erl @@ -909,9 +909,25 @@ read_application_data(Data, try read_application_dist_data(DHandle, Front, BufferSize, Rear) of Buffer -> {no_record, State#state{user_data_buffer = Buffer}} - catch error:_ -> - {stop,disconnect, - State#state{user_data_buffer = {Front,BufferSize,Rear}}} + catch + error:notsup -> + %% Distribution controller has shut down + %% so we are no longer input handler and therefore + %% erlang:dist_ctrl_put_data/2 raises this exception + {stop, {shutdown, dist_closed}, + %% This buffers known data, but we might have delivered + %% some of it to the VM, which makes buffering all + %% incorrect, as would be wasting all. + %% But we are stopping the server so + %% user_data_buffer is not important at all... + State#state{ + user_data_buffer = {Front,BufferSize,Rear}}}; + error:Reason:Stacktrace -> + %% Unforeseen exception in parsing application data + {stop, + {disconnect,{error,Reason,Stacktrace}}, + State#state{ + user_data_buffer = {Front,BufferSize,Rear}}} end end. passive_receive(#state{user_data_buffer = {Front,BufferSize,Rear}, diff --git a/lib/ssl/src/tls_sender.erl b/lib/ssl/src/tls_sender.erl index 68e4eeed4e..2d3f8f4f79 100644 --- a/lib/ssl/src/tls_sender.erl +++ b/lib/ssl/src/tls_sender.erl @@ -384,14 +384,18 @@ handshake(Type, Msg, StateData) -> StateData :: term()) -> gen_statem:event_handler_result(atom()). %%-------------------------------------------------------------------- -death_row(state_timeout, Reason, _State) -> +death_row(state_timeout, Reason, _StateData) -> {stop, {shutdown, Reason}}; -death_row(info = Type, Msg, State) -> - handle_common(Type, Msg, State); -death_row(_Type, _Msg, _State) -> +death_row(info = Type, Msg, StateData) -> + handle_common(Type, Msg, StateData); +death_row(_Type, _Msg, _StateData) -> %% Waste all other events keep_state_and_data. +%% State entry function that starts shutdown state_timeout +death_row_shutdown(Reason, StateData) -> + {next_state, death_row, StateData, [{state_timeout, 5000, Reason}]}. + %%-------------------------------------------------------------------- -spec terminate(Reason :: term(), State :: term(), Data :: term()) -> any(). @@ -422,14 +426,14 @@ handle_common({call, From}, {set_opts, Opts}, #data{static = #static{socket_options = SockOpts} = Static} = StateData) -> {keep_state, StateData#data{static = Static#static{socket_options = set_opts(SockOpts, Opts)}}, [{reply, From, ok}]}; -handle_common(info, {'EXIT', _Sup, shutdown}, +handle_common(info, {'EXIT', _Sup, shutdown = Reason}, #data{static = #static{erl_dist = true}} = StateData) -> %% When the connection is on its way down operations - %% begin to fail. We wait for 5 seconds to receive - %% possible exit signals for one of our links to the other - %% involved distribution parties, in which case we want to use - %% their exit reason for the connection teardown. - {next_state, death_row, StateData, [{state_timeout, 5000, shutdown}]}; + %% begin to fail. We wait to receive possible exit signals + %% for one of our links to the other involved distribution parties, + %% in which case we want to use their exit reason + %% for the connection teardown. + death_row_shutdown(Reason, StateData); handle_common(info, {'EXIT', _Dist, Reason}, #data{static = #static{erl_dist = true}} = StateData) -> {stop, {shutdown, Reason}, StateData}; @@ -493,7 +497,7 @@ send_application_data(Data, From, StateName, StateData1 = update_bytes_sent(Version, StateData, Data), {next_state, StateName, StateData1, []}; Reason when DistHandle =/= undefined -> - {next_state, death_row, StateData, [{state_timeout, 5000, Reason}]}; + death_row_shutdown(Reason, StateData); ok -> ssl_logger:debug(LogLevel, outbound, 'record', Msgs), StateData1 = update_bytes_sent(Version, StateData, Data), @@ -522,7 +526,7 @@ send_post_handshake_data(Handshake, From, StateName, StateData = maybe_update_cipher_key(StateData1, Handshake), {next_state, StateName, StateData, []}; Reason when DistHandle =/= undefined -> - {next_state, death_row, StateData1, [{state_timeout, 5000, Reason}]}; + death_row_shutdown(Reason, StateData1); ok -> ssl_logger:debug(LogLevel, outbound, 'record', Encoded), StateData = maybe_update_cipher_key(StateData1, Handshake), diff --git a/lib/ssl/test/inet_crypto_dist.erl b/lib/ssl/test/inet_crypto_dist.erl index 58a303f48c..0c272f75ec 100644 --- a/lib/ssl/test/inet_crypto_dist.erl +++ b/lib/ssl/test/inet_crypto_dist.erl @@ -960,8 +960,8 @@ init_msg( MsgLen = byte_size(R1A) + TagLen + iolist_size(Plaintext), AAD = [<<MsgLen:32>>, R1A], {Ciphertext, Tag} = - crypto:crypto_one_time(AeadCipher, Key1A, IV1A, - {AAD, Plaintext, TagLen}, true), + crypto:crypto_one_time_aead( + AeadCipher, Key1A, IV1A, Plaintext, AAD, TagLen, true), Msg = [R1A, Tag, Ciphertext], {R2A, R3A, Msg}. %% @@ -982,8 +982,8 @@ init_msg( MsgLen = byte_size(Msg), AAD = [<<MsgLen:32>>, R1B], case - crypto:crypto_one_time( - AeadCipher, Key1B, IV1B, {AAD, Ciphertext, Tag}, false) + crypto:crypto_one_time_aead( + AeadCipher, Key1B, IV1B, Ciphertext, AAD, Tag, false) of <<R2B:RLen/binary, R3B:RLen/binary, PubKeyB/binary>> -> SharedSecret = compute_shared_secret(KeyPair, PubKeyB), @@ -1000,8 +1000,9 @@ init_msg( StartMsgLen = TagLen + iolist_size(StartCleartext), StartAAD = <<StartMsgLen:32>>, {StartCiphertext, StartTag} = - crypto:crypto_one_time(AeadCipher, Key2A, IV2A, - {StartAAD, StartCleartext, TagLen}, true), + crypto:crypto_one_time_aead( + AeadCipher, Key2A, IV2A, + StartCleartext, StartAAD, TagLen, true), StartMsg = [StartTag, StartCiphertext], %% {Key2B, IV2B} = @@ -1032,8 +1033,8 @@ start_msg( MsgLen = byte_size(Msg), AAD = <<MsgLen:32>>, case - crypto:crypto_one_time( - AeadCipher, Key2B, IV2B, {AAD, Ciphertext, Tag}, false) + crypto:crypto_one_time_aead( + AeadCipher, Key2B, IV2B, Ciphertext, AAD, Tag, false) of <<R2A:RLen/binary, R3A:RLen/binary, RekeyCountB:32>> when RekeyCountA =< (RekeyCountB bsl 2), @@ -1044,7 +1045,7 @@ start_msg( hmac_key_iv(HmacAlgo, MacKey, Data, KeyLen, IVLen) -> <<Key:KeyLen/binary, IV:IVLen/binary>> = - crypto:macN(HmacAlgo, MacKey, Data, KeyLen + IVLen), + crypto:macN(hmac, HmacAlgo, MacKey, Data, KeyLen + IVLen), {Key, IV}. %% ------------------------------------------------------------------------- @@ -1455,8 +1456,8 @@ encrypt_chunk( AAD = <<Seq:32, ChunkLen:32>>, IVBin = <<IVSalt/binary, (IVNo + Seq):48>>, {Ciphertext, CipherTag} = - crypto:crypto_one_time(AeadCipher, Key, IVBin, - {AAD, Cleartext, TagLen}, true), + crypto:crypto_one_time_aead( + AeadCipher, Key, IVBin, Cleartext, AAD, TagLen, true), Chunk = [Ciphertext,CipherTag], Chunk. @@ -1478,7 +1479,7 @@ decrypt_chunk( CipherTag:TagLen/binary>> -> block_decrypt( Params, Seq, AeadCipher, Key, IVBin, - {AAD, Ciphertext, CipherTag}); + Ciphertext, AAD, CipherTag); _ -> error end @@ -1488,8 +1489,11 @@ block_decrypt( #params{ rekey_key = #key_pair{public = PubKeyA} = KeyPair, rekey_count = RekeyCount} = Params, - Seq, AeadCipher, Key, IV, Data) -> - case crypto:crypto_one_time(AeadCipher, Key, IV, Data, false) of + Seq, AeadCipher, Key, IV, Ciphertext, AAD, CipherTag) -> + case + crypto:crypto_one_time_aead( + AeadCipher, Key, IV, Ciphertext, AAD, CipherTag, false) + of <<?REKEY_CHUNK, Rest/binary>> -> PubKeyLen = byte_size(PubKeyA), case Rest of diff --git a/lib/ssl/test/ssl_dist_bench_SUITE.erl b/lib/ssl/test/ssl_dist_bench_SUITE.erl index f110931930..58d9b92e0b 100644 --- a/lib/ssl/test/ssl_dist_bench_SUITE.erl +++ b/lib/ssl/test/ssl_dist_bench_SUITE.erl @@ -625,6 +625,47 @@ throughput_runner(A, B, Rounds, Size) -> client_msacc_stats => MsaccStats, client_prof => Prof}. +dig_dist_node_sockets() -> + DistCtrl2Node = + maps:from_list( + [{DistCtrl, Node} + || {Node, DistCtrl} + <- erlang:system_info(dist_ctrl), is_pid(DistCtrl)]), + TlsDistConnSup = whereis(tls_dist_connection_sup), + InetCryptoDist = whereis(inet_crypto_dist), + [NodeSocket + || {_, Socket} = NodeSocket + <- erlang:system_info(dist_ctrl), is_port(Socket)] + ++ + if + TlsDistConnSup =/= undefined -> + [case ConnSpec of + {undefined, ConnSup, supervisor, _} -> + [{receiver, ReceiverPid, worker, _}, + {sender, SenderPid, worker, _}] = + lists:sort(supervisor:which_children(ConnSup)), + {links,ReceiverLinks} = + process_info(ReceiverPid, links), + [Socket] = [S || S <- ReceiverLinks, is_port(S)], + {maps:get(SenderPid, DistCtrl2Node), Socket} + end + || ConnSpec <- supervisor:which_children(TlsDistConnSup)]; + InetCryptoDist =/= undefined -> + [begin + {monitors,[{process,InputHandler}]} = + erlang:process_info(DistCtrl, monitors), + {links,InputHandlerLinks} = + erlang:process_info(InputHandler, links), + [Socket] = + [S || S <- InputHandlerLinks, is_port(S)], + {Node, Socket} + end + || {DistCtrl, Node} <- maps:to_list(DistCtrl2Node)]; + true -> + [] + end. + +-ifdef(undefined). dig_dist_node_sockets() -> [case DistCtrl of {_Node,Socket} = NodeSocket when is_port(Socket) -> @@ -643,7 +684,7 @@ dig_dist_node_sockets() -> {Node,Socket} end end || DistCtrl <- erlang:system_info(dist_ctrl)]. - +-endif. throughput_server(Pid, N) -> GC_Before = get_server_gc_info(), -- 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