Marat
Marat

Reputation: 337

Error during starting the application with cowboy example ('noproc', ranch_listener_sup)

I'm trying run this cowboy example using rebar3: cowboy version 2.0.0-pre.5

What I do is:

  1. rebar3 new app hello_world
  2. copy the example src into my src
  3. updating rebar.config {cowboy,".*", {git, "https://github.com/ninenines/cowboy", {branch, "master"}}}
  4. rebar3 compile. Everything go fine
  5. erl -pa _build/default/lib/*/ebin
  6. application:start(hello_world).

then error occurs

{error,{bad_return,{{hello_world_app,start,[normal,[]]},
                    {'EXIT',{noproc,{gen_server,call,
                                                [ranch_sup,
                                                 {start_child,{{ranch_listener_sup,http},
                                                               {ranch_listener_sup,start_link,
                                                                                   [http,100,ranch_tcp,
                                                                                    [{connection_type,supervisor},{port,...}],
                                                                                    cowboy_clear,
                                                                                    #{connection_type => supervisor,...}]},
                                                               permanent,infinity,supervisor,
                                                               [ranch_listener_sup]}},
                                                 infinity]}}}}}}

=INFO REPORT==== 24-Jan-2017::18:34:52 ===
    application: hello_world
    exited: {bad_return,
                {{hello_world_app,start,[normal,[]]},
                 {'EXIT',
                     {noproc,
                         {gen_server,call,
                             [ranch_sup,
                              {start_child,
                                  {{ranch_listener_sup,http},
                                   {ranch_listener_sup,start_link,
                                       [http,100,ranch_tcp,
                                        [{connection_type,supervisor},
                                         {port,8080}],
                                        cowboy_clear,
                                        #{connection_type => supervisor,
                                          env => #{dispatch => [{'_',[],
                                                 [{[],[],toppage_handler,
                                                   []}]}]}}]},
                                   permanent,infinity,supervisor,
                                   [ranch_listener_sup]}},
                              infinity]}}}}}
    type: temporary

It seems that runch_sup can't start. What's wrong with my approach? I want to run exactly the same src code as in example.

Upvotes: 1

Views: 588

Answers (2)

vlence
vlence

Reputation: 495

For anyone else stuck on this issue you just need to make sure ranch is started before your application is started. To do this edit the src/my_app.app.src file like so:

{application, my_app,
 [{description, "An OTP application"},
  {vsn, "0.1.0"},
  {registered, []},
  {mod, {my_app_app, []}},
  {applications,
   [kernel,
    stdlib,
    ranch
   ]},
  {env,[]},
  {modules, []},

  {licenses, ["Apache-2.0"]},
  {links, []}
 ]}.

Notice that ranch has been added as an application after kernel and stdlib.

Upvotes: 1

Marat
Marat

Reputation: 337

Ranch 1.3 depends on the ssl application by default. If you don't start it, Ranch fails to start. I would recommend matching on ok when doing ok = application:start(App), you'd have known the issue much quicker.

by essen

here is the issue

Upvotes: 0

Related Questions