Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The Ranch application with SSL listener fails after calling init:stop/0 in Erlang/OTP 17.1 and 17.3 #90

Closed
vicbaz opened this issue Oct 2, 2014 · 10 comments
Milestone

Comments

@vicbaz
Copy link
Contributor

vicbaz commented Oct 2, 2014

$ 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_world_example@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_world_example@127.0.0.1)2> init:stop().
ok
(ssl_hello_world_example@127.0.0.1)3>
=ERROR REPORT==== 29-Sep-2014::16:49:15 ===
Error in process <0.69.0> on node 'ssl_hello_world_example@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_world_example@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. The ranch_acceptors_sup shuts down the ranch application because of the maximum number of restarts. This forces all other applications to be also terminated. But the entire Erlang node remains running.

What is the purpose of this guard? As mentioned in the erlang-questions mailing list, the listener socket can be closed before the ranch application has finished its shutdown. And this behaviour is considered normal.

@chaehb
Copy link

chaehb commented Oct 6, 2014

I have struggled the same issue after erlang/otp 17.1.

@essen
Copy link
Member

essen commented Nov 5, 2014

If the listening socket got closed, we need to reopen it, therefore we crash here so the error bubbles up the supervision tree until the code that reopens the socket.

The relevant mailing list discussion can be found at http://erlang.org/pipermail/erlang-questions/2014-October/081183.html

This code should not be triggered on shutdown as these processes are brutally killed.

The issue comes from the application start/stop order. If you make Ranch depend on SSL, everything works correctly. What I am unsure of is what has changed that makes code that worked before 17.1 to suddenly stop working, though.

@vicbaz
Copy link
Contributor Author

vicbaz commented Nov 7, 2014

Thank you for the clarification. I think this issue can be closed.

@vicbaz vicbaz closed this as completed Nov 7, 2014
@essen
Copy link
Member

essen commented Nov 7, 2014

I will keep it open for now as I need to investigate further, so this will be my reminder. Thanks for the report!

@essen essen reopened this Nov 7, 2014
@MarkNijhof
Copy link

Hi @essen ,
How do I make Ranch depend on SSL to it prevents the crash on stop?

@vicbaz
Copy link
Contributor Author

vicbaz commented Nov 13, 2014

sed is your friend.

I do this:

include erlang.mk

deps::
    sed -i 's/\(stdlib\)$$/\1,\n\t\tssl/' deps/ranch/ebin/ranch.app

@MarkNijhof
Copy link

Awesome, thanks for that tip

@justnoxx
Copy link

Hi, after erlang upgrade to r18 I have this issue again. Proposed solution with sed has no effect.

@justnoxx
Copy link

Fixed sed command:

sed -i 's/\(stdlib\)/\1,\t\tssl/' deps/ranch/ebin/ranch.app

@essen essen added this to the 2.0.0 milestone Aug 13, 2015
@essen essen added the Bug label Aug 14, 2015
@essen essen modified the milestones: 1.3.0, 2.0.0 Nov 15, 2016
@essen
Copy link
Member

essen commented Nov 15, 2016

So this is fixed in my local copy. Push later and will be in 1.3.0. Closing, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants