[erlang-questions] Abandoned (ranch) connection processes?

Roger Lipscombe roger@REDACTED
Thu Feb 15 13:29:43 CET 2018


It's a server, not a client, which might make some difference. So
here's my repro:

    Port = 12090.
    CertFile = CertPath ++ "server.pem".
    KeyFile = CertPath ++ "server.key".

    {ok, _} = application:ensure_all_started(ssl).

    LOpts = [binary, {active, false}, {packet, raw}, {reuseaddr,
true}, {nodelay, true},
                  {certfile, CertFile},
                  {keyfile, KeyFile}].

    {ok, LSocket} = ssl:listen(Port, LOpts).
    {ok, CSocket} = ssl:transport_accept(LSocket, infinity).
    ok = ssl:ssl_accept(CSocket, infinity).

    % At this point:
    % openssl s_client -connect localhost:12090 -CAfile $CAFile

    ok = ssl:setopts(CSocket, [{active, once}]).
    flush().

If I kill openssl (with Ctrl+C) before the setopts call, it returns
ok, and I get the ssl_closed message.


On 15 February 2018 at 11:56, Fred Hebert <mononcqc@REDACTED> wrote:
> On 02/15, Roger Lipscombe wrote:
>>
>> OK. Let me rephrase that:
>>
>> - {active, once} obviously has something in place to handle data
>> arriving and closed sockets *in between* calls to {active, once} --
>> i.e. it'll be {active, false} for a brief interval. I last looked at
>> this code in 17.x (before the gen_statem refactoring), so I'm not sure
>> where it lives now.
>> - does it deal correctly with closed sockets that close before the
>> *first* call to {active, once}? In other words: can I expect an
>> ssl_closed message in this case? Is there something special about the
>> first call?
>>
>
> Nothing like a quick experiment to show:
>
>    5> {ok, S} = ssl:connect("google.com", 443, [{active, false}]).
>    {ok,{sslsocket,{gen_tcp,#Port<0.953>,tls_connection,
>                            undefined},
>                   <0.91.0>}}
>    6> ssl:close(S).
>    ok
>    7> ssl:setopts(S, [{active,once}]).
>    {error,closed}
>    8> flush().
>    ok
>
> It looks like you do have to check the result of setopts to find that the
> connections has failed early.



More information about the erlang-questions mailing list