[erlang-questions] The node (with release using ssl) does not shut down after calling init:stop/0 in Erlang 17.3

42 views
Skip to first unread message

a a

unread,
Sep 30, 2014, 10:13:59 AM9/30/14
to erlang-q...@erlang.org
Hello,

I use Erlang 17.3 downloaded from
https://www.erlang-solutions.com/downloads/download-erlang-otp

When I am trying to stop the ssl_hello_world example from cowboy I have encountered a strange behaviour.

$ git clone https://github.com/ninenines/cowboy
$ cd cowboy
$ git checkout 1.0.0
$ cd examples/ssl_hello_world
$ make
$ ./_rel/ssl_hello_world_example/bin/ssl_hello_world_example console

Erlang/OTP 17 [erts-6.2] [source-5c974be] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false]

Eshell V6.2  (abort with ^G)
(ssl_hello_w...@127.0.0.1)1> application:which_applications().
[{ssl_hello_world,"Cowboy Hello World example with SSL.",
                            "1"},
 {ssl,"Erlang/OTP SSL application","5.3.6"},
 {cowboy,"Small, fast, modular HTTP server.","1.0.0"},
 {cowlib,"Support library for manipulating Web protocols.",
             "1.0.0"},
 {public_key,"Public key infrastructure","0.22.1"},
 {crypto,"CRYPTO","3.4.1"},
 {ranch,"Socket acceptor pool for TCP protocols.","1.0.0"},
 {asn1,"The Erlang ASN1 compiler version 3.0.2","3.0.2"},
 {stdlib,"ERTS  CXC 138 10","2.2"},
 {kernel,"ERTS  CXC 138 10","3.0.3"}]
(ssl_hello_w...@127.0.0.1)2> init:stop().
ok
(ssl_hello_w...@127.0.0.1)3>
=ERROR REPORT==== 29-Sep-2014::16:49:15 ===
Error in process <0.69.0> on node 'ssl_hello_w...@127.0.0.1' with exit value: {{case_clause,{error,closed}},[{ranch_acceptor,loop,3,[{file,"src/ranch_acceptor.erl"},{line,28}]}]}
...
=ERROR REPORT==== 29-Sep-2014::16:49:15 ===
Error in process <0.164.0> on node 'ssl_hello_w...@127.0.0.1' with exit value: {{case_clause,{error,closed}},[{ranch_acceptor,loop,3,[{file,"src/ranch_acceptor.erl"},{line,28}]}]}

The listener socket has been closed.
It seems the node is still running, but:

(ssl_hello_w...@127.0.0.1)3> application:which_applications().
** exception exit: {timeout,{gen_server,call,
                                                              [application_controller,which_applications]}}
        in function  gen_server:call/2 (gen_server.erl, line 182)

If I change this line
https://github.com/ninenines/ranch/blob/1.0.0/src/ranch_acceptor.erl#L40
to
     {error, _Reason} -> ok
the acceptor processes do not crash after calling init:stop/0, and the node shuts down correctly.

This behavour appears only in Erlang 17.3 (I have tried it in Debian 7.6, Ubuntu 12.04.5, OS X 10.9.5). In Erlang R16B03 everything seems to work correctly.

What else can I do to reveal the cause of this issue?

Ingela Andin

unread,
Sep 30, 2014, 10:35:45 AM9/30/14
to a a, Erlang-Questions Questions
Hi!

If you apply the following patch to 17.3 it might help. The SNI-contribution that we included in this release had missed the detail, that the server may optionally send a
SNI-extension that must be empty.

diff --git a/lib/ssl/src/ssl_handshake.
erl b/lib/ssl/src/ssl_handshake.erl
index 22673e4..eee33ef 100644
--- a/lib/ssl/src/ssl_handshake.erl
+++ b/lib/ssl/src/ssl_handshake.erl
@@ -1732,6 +1732,9 @@ dec_hello_extensions(<<?UINT16(?EC_POINT_FORMATS_EXT), ?UINT16(Len),
                             #ec_point_formats{ec_point_format_list =
                                           ECPointFormats}});
 
+dec_hello_extensions(<<?UINT16(?SNI_EXT), ?UINT16(Len), Rest/binary>>, Acc) when Len == 0 ->
+    dec_hello_extensions(Rest, Acc#hello_extensions{sni = ""}); %% Server may send an empy SNI
+
 dec_hello_extensions(<<?UINT16(?SNI_EXT), ?UINT16(Len),
                 ExtData:Len/binary, Rest/binary>>, Acc) ->
     <<?UINT16(_), NameList/binary>> = ExtData,


_______________________________________________
erlang-questions mailing list
erlang-q...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions


buddy

unread,
Oct 1, 2014, 11:44:32 AM10/1/14
to Ingela Andin, Erlang-Questions Questions
Hello,

It seems the patch is not related to the issue. But I have tried your
patch and it does not help.

Moreover, I have tried the ssl_hello_world example (as mentioned
below) in Erlang 17.0 and it works correctly.

$ ./_rel/ssl_hello_world_example/bin/ssl_hello_world_example console
Erlang/OTP 17 [erts-6.0] [source-07b8f44] [64-bit] [smp:4:4]
[async-threads:10] [hipe] [kernel-poll:false] [dtrace]

Eshell V6.0 (abort with ^G)
(ssl_hello_w...@127.0.0.1)1> application:which_applications().
[{ssl_hello_world,"Cowboy Hello World example with SSL.",
"1"},
{ssl,"Erlang/OTP SSL application","5.3.4"},
{cowboy,"Small, fast, modular HTTP server.","1.0.0"},
{cowlib,"Support library for manipulating Web protocols.",
"1.0.0"},
{public_key,"Public key infrastructure","0.22"},
{crypto,"CRYPTO","3.3"},
{ranch,"Socket acceptor pool for TCP protocols.","1.0.0"},
{asn1,"The Erlang ASN1 compiler version 3.0","3.0"},
{stdlib,"ERTS CXC 138 10","2.0"},
{kernel,"ERTS CXC 138 10","3.0"}]
(ssl_hello_w...@127.0.0.1)2> init:stop().
ok
(ssl_hello_w...@127.0.0.1)3> %
$

In 17.1 it failed on init:stop/0. The similar behaviour was in 17.3.
Thus, the problem has occurred somewhere after 17.0. What else can I
do to resolve this issue?

buddy

unread,
Oct 1, 2014, 5:13:44 PM10/1/14
to Ingela Andin, Erlang-Questions Questions
It occurs the ssl listener socket now closes before the ranch
application is shutdown. Сan this behaviour be considered as normal?

Ingela Andin

unread,
Oct 1, 2014, 5:31:02 PM10/1/14
to buddy, Erlang-Questions Questions
Hi!


2014-10-01 23:13 GMT+02:00 buddy <tauce...@gmail.com>:
It occurs the ssl listener socket now closes before the ranch
application is shutdown. Сan this behaviour be considered as normal?

I am not so familiar with the ranch application, but as the ranch application uses the ssl application it sounds normal that a ssl listen socket can be closed before the ranch application has finished its shutdown.  Timing of  events of course can change between releases or platforms running the same release.  

Regards Ingela Erlang/OTP team - Ericsson AB

buddy

unread,
Oct 2, 2014, 4:18:56 AM10/2/14
to Ingela Andin, Erlang-Questions Questions
Hello Ingela,

Thank you for clarification!

Loïc Hoguin

unread,
Oct 3, 2014, 11:07:13 AM10/3/14
to Ingela Andin, buddy, Erlang-Questions Questions
Hi,

On 10/02/2014 12:30 AM, Ingela Andin wrote:
> Hi!
>
> 2014-10-01 23:13 GMT+02:00 buddy <tauce...@gmail.com

> <mailto:tauce...@gmail.com>>:


>
> It occurs the ssl listener socket now closes before the ranch
> application is shutdown. Сan this behaviour be considered as normal?
>
>
> I am not so familiar with the ranch application, but as the ranch
> application uses the ssl application it sounds normal that a ssl listen
> socket can be closed before the ranch application has finished its
> shutdown. Timing of events of course can change between releases or
> platforms running the same release.

It is not normal and there should be no timing issue involved.

The processes are like this:

supervisor owns the listening socket
|-> children do the accept

When the application is stopped, the children are killed with
brutal_kill by the supervisor, which then proceeds to end (and thus
closes the listening socket).

So this is not a timing issue as the termination order does not allow
for this scenario, or at least not one where the application closes the
socket before the children who accept connections.

On the other hand the supervisor has a terminate value set to infinity
(the recommended for supervisors) so this might be part of the reason
why it ends up causing errors/not stopping the VM, and could be
unrelated to SSL (though it apparently only happens with SSL listeners
from what I understand). Something else could prevent the application
from stopping properly.

A ticket has been open on the Ranch tracker so I will investigate
further when I get the time.

--
Loïc Hoguin
http://ninenines.eu

Reply all
Reply to author
Forward
0 new messages