Skip to content

Commit

Permalink
Avoid SSL deadlock
Browse files Browse the repository at this point in the history
This patch works around deadlocks that occur when sending data
bidirectionally using Erlang SSL sockets. It is possible that both sides
send enough data to fill up the buffers and block, without either side
being able to read data to empty the other side's buffer.  This is
typically avoided by having different processes handle the reading and
writing duties. But the Erlang SSL library uses a single gen_fsm for
both.
  • Loading branch information
engelsanchez committed Dec 19, 2014
1 parent 163d3e4 commit e237383
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions lib/ssl/src/tls_connection.erl
Expand Up @@ -2355,9 +2355,21 @@ write_application_data(Data0, From, #state{socket = Socket,
renegotiation = {true, internal}});
false ->
{Msgs, ConnectionStates} = ssl_record:encode_data(Data, Version, ConnectionStates0),
Result = Transport:send(Socket, Msgs),
{reply, Result,
connection, State#state{connection_states = ConnectionStates}, get_timeout(State)}
Active = case erlang:port_info(Socket, queue_size) of
Size when Size > 8192 ->
{ok, [{active, A}]} = inet:getopts(Socket, [active]),
inet:setopts(Socket, [{active,true}]),
A;
_ ->
undefined
end,
Result = Transport:send(Socket, Msgs),
case Active of
undefined -> ok;
_ -> inet:setopts(Socket, [{active,Active}])
end,
{reply, Result,
connection, State#state{connection_states = ConnectionStates}, get_timeout(State)}
end.

time_to_renegotiate(_Data, #connection_states{current_write =
Expand Down

2 comments on commit e237383

@hazen
Copy link

@hazen hazen commented on e237383 Dec 20, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@engelsanchez Do we want to bump the version string in erts/vsn.mk to R16B02-basho7, too? Just looking at what Jared did last time.

@engelsanchez
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll leave that to Greg if he decides. I don't really know my way around these things.

Please sign in to comment.