Skip to content

Commit

Permalink
fixup! Garbage collect after conn setup
Browse files Browse the repository at this point in the history
  • Loading branch information
dgud committed Feb 16, 2024
1 parent 59cc926 commit 7ddc07a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
16 changes: 10 additions & 6 deletions lib/ssl/src/dtls_gen_connection.erl
Original file line number Diff line number Diff line change
Expand Up @@ -579,17 +579,21 @@ queue_change_cipher(ChangeCipher, #state{handshake_env =
HsEnv = HsEnv0#handshake_env{flight_buffer = Flight#{change_cipher_spec => ChangeCipher}},
State#state{handshake_env = HsEnv, connection_states = ConnectionStates}.

reinit(State) ->
reinit(State0) ->
%% To be API compatible with TLS NOOP here
reinit_handshake_data(State).
State = reinit_handshake_data(State0),
garbage_collect(),
State.

reinit_handshake_data(#state{static_env = #static_env{data_tag = DataTag},
protocol_buffers = Buffers,
protocol_specific = PS,
handshake_env = HsEnv} = State) ->
State#state{handshake_env = HsEnv#handshake_env{tls_handshake_history = ssl_handshake:init_handshake_history(),
public_key_info = undefined,
premaster_secret = undefined,
flight_buffer = new_flight()},
State#state{handshake_env = HsEnv#handshake_env{
tls_handshake_history = ssl_handshake:init_handshake_history(),
public_key_info = undefined,
premaster_secret = undefined,
flight_buffer = new_flight()},
protocol_specific = PS#{flight_state => initial_flight_state(DataTag)},
protocol_buffers =
Buffers#protocol_buffers{
Expand Down
20 changes: 11 additions & 9 deletions lib/ssl/src/tls_gen_connection.erl
Original file line number Diff line number Diff line change
Expand Up @@ -224,20 +224,22 @@ queue_change_cipher(Msg, #state{connection_env = #connection_env{negotiated_vers

reinit(#state{protocol_specific = #{sender := Sender},
connection_env = #connection_env{negotiated_version = Version},
connection_states = #{current_write := Write}} = State) ->
connection_states = #{current_write := Write}} = State0) ->
tls_sender:update_connection_state(Sender, Write, Version),
reinit_handshake_data(State).
State = reinit_handshake_data(State0),
garbage_collect(),
State.

reinit_handshake_data(#state{handshake_env = HsEnv} =State) ->
reinit_handshake_data(#state{handshake_env = HsEnv} = State) ->
%% premaster_secret, public_key_info and tls_handshake_info
%% are only needed during the handshake phase.
%% To reduce memory foot print of a connection reinitialize them.
State#state{
handshake_env = HsEnv#handshake_env{tls_handshake_history =
ssl_handshake:init_handshake_history(),
public_key_info = undefined,
premaster_secret = undefined}
}.
State#state{handshake_env =
HsEnv#handshake_env{tls_handshake_history =
ssl_handshake:init_handshake_history(),
public_key_info = undefined,
premaster_secret = undefined}
}.

select_sni_extension(#client_hello{extensions = #{sni := SNI}}) ->
SNI;
Expand Down
1 change: 0 additions & 1 deletion lib/ssl/src/tls_gen_connection_1_3.erl
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ wait_cv(Type, Msg, State) ->
ssl_gen_statem:handle_common_event(Type, Msg, ?STATE(wait_cv), State).

connection(enter, _, State) ->
garbage_collect(),
{keep_state, State};
connection(internal, #new_session_ticket{} = NewSessionTicket, State) ->
handle_new_session_ticket(NewSessionTicket, State),
Expand Down

0 comments on commit 7ddc07a

Please sign in to comment.