Book "Programming Phoenix 1.4" => failed to start child: RumblWeb.Presence

Hi,

I am reading “Programming Phoenix 1.4” and now on 265p.

To run sample codes of the book, I have input necessary commands into the terminal such as “mix deps.get”, “mix deps.update --all”, “cd assets && npm install force” commands in order. Most sample codes(such as umbrella projects) in the books show a similar error message as below. I could fix errors of some samples(such as “authentication”), but mostly not.

Error message

[warn] no configuration found for otp_app :rumbl_web and module RumblWeb.Endpoint
[info] Application rumbl_web exited: RumblWeb.Application.start(:normal, []) returned an error: shutdown: failed to start child: RumblWeb.Presence
    ** (EXIT) shutdown: failed to start child: Phoenix.Tracker
        ** (EXIT) shutdown: failed to start child: RumblWeb.Presence_shard0
            ** (EXIT) an exception was raised:
                ** (ArgumentError) argument error
                    (stdlib) :ets.lookup(RumblWeb.PubSub, :node_name)
                    (phoenix_pubsub) lib/phoenix/pubsub.ex:288: Phoenix.PubSub.call/3
                    (rumbl_web) lib/rumbl_web/channels/presence.ex:10: RumblWeb.Presence.init/1
                    (phoenix_pubsub) lib/phoenix/tracker/shard.ex:120: Phoenix.Tracker.Shard.init/1
                    (stdlib) gen_server.erl:374: :gen_server.init_it/2
                    (stdlib) gen_server.erl:342: :gen_server.init_it/6
                    (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3

I am using macOS High Sierra, and I uploaded the error projects onto github.

The uploaded sample code has two small projects: “rumbl” and “rumbl_web”. The former works fine, and the latter shows the error message above.

Another sample code showing the same error message.

I expect some help from the readers of the book. Always thank you.

PS> I guess the problem is in “config” as the message says.

[warn] no configuration found for otp_app :rumbl_web and module RumblWeb.Endpoint

But, I can’t figure it out to fix it.

PS 2>
After commenting out “RumblWeb.Presence” from the children list in “RumblWeb.Application.start()”, the sample projects works without “Presence” function. So, the issue is from “Presence” module. How to fix it work?

config :rumbl, RumblWeb.Endpoint,
  url: [host: "localhost"],
  secret_key_base: "21zZTQte+xBJVK8nAa9Q+Rn+bcz3xJsSoilWKIDCY8kl0eht5QdOmydLIG8n7ZhW",
  render_errors: [view: RumblWeb.ErrorView, accepts: ~w(html json)],
  pubsub: [name: Rumbl.PubSub, adapter: Phoenix.PubSub.PG2]

should be config :rumbl_web ...

In particular presence is failing since it uses Phoenix.PubSub and expects its home app to be compiled with these configurations which were routed to the :rumbl app in your umbrella and not :rumbl_web app.

Thank you for help, ityonemo.

I have already fixed config :rumbl_web after posting this question, but still not works.

What about the second sample " team-jupeter/rumbl_umbrella".

Your pubsub name in the config is Rumbl.PubSub and your presence module expects RumblWeb.PubSub

6 Likes

Perfect explanation. It works.

I should learn the role of config file.

Would you recommend some learning materials? official sites are too brief.
https://hexdocs.pm/mix/Mix.Config.html

I really wish I could, but the way I learned how to debug config files was by struggling with understanding them myself. =( Perhaps someone else can suggest good resources?

1 Like

I see.
Thank you from a few Korean developers and me :grin: .

1 Like

Hi

Some ideas that use:

  • migrations schemas and context goes in lib your app modules namespaces

  • channels

  • controllers

  • views

  • templates

go under app_web domain space

I hope this helps.

Also this helped me a lot https://shankardevy.com/phoenix-inside-out-mpf/

1 Like

Thanks wolfiton, I will check the document and share it with my fellows.

1 Like

You are welcome, also I have series here https://dev.to/wolfiton/absinthe-journey-with-wolfiton-or-how-to-bring-the-absinthe-tutorial-up-to-date-part-1-introduction-5fgg

1 Like

I have just noticed it. Thank you again, wolfiton.

1 Like

You are welcome

1 Like

I was able to fix this by also adding Phoenix.PubSub with name as RumblWeb.PubSub as a child in apps/rumbl_web/application.ex

children = [
  RumblWeb.Endpoint,
  {Phoenix.PubSub, name: RumblWeb.PubSub},
  RumblWeb.Presence
]
3 Likes

Thanks for sharing this! It solved the issue for me too.

1 Like

Thanks so much by the help guys.

In the end I’ve made two changes only:

Changes the: rumbl_umbrella/config/config.exs, like suggested by @ityonemo

From this

config :rumbl_web, RumblWeb.Endpoint,
  ...
  pubsub_server: Rumbl.PubSub

To this

config :rumbl_web, RumblWeb.Endpoint,
  ...
  pubsub_server: RumblWeb.PubSub

And following the @kabisote suggestion:

Change the rumbl_umbrella/apps/rumbl_web/application.ex

From this:


    children = [
      # Start the Telemetry supervisor
      RumblWeb.Telemetry,
      # Start the Endpoint (http/https)
      RumblWeb.Endpoint,
      RumblWeb.Presence
      # Start a worker by calling: RumblWeb.Worker.start_link(arg)
      # {RumblWeb.Worker, arg}
    ]

To this:


    children = [
      # Start the Telemetry supervisor
      RumblWeb.Telemetry,
      # Start the Endpoint (http/https)
      RumblWeb.Endpoint,
      {Phoenix.PubSub, name: RumblWeb.PubSub},
      RumblWeb.Presence
      # Start a worker by calling: RumblWeb.Worker.start_link(arg)
      # {RumblWeb.Worker, arg}
    ]
2 Likes

What this topic has made me realize is that, the ordering of the child applications in your application.ex matters. The whole time my children list was like this:

    children = [
      # Start the Telemetry supervisor
      # RumblWeb.Telemetry,
      # Start the Endpoint (http/https)
      RumblWeb.Endpoint,
      RumblWeb.Presence,
      {Phoenix.PubSub, name: RumblWeb.PubSub},
      # Start a worker by calling: RumblWeb.Worker.start_link(arg)
      # {RumblWeb.Worker, arg}
    ]

So if you’ve got Presence before PubSub you get the error below when you try mix phx.server:

╰─$ mix phx.server
==> rumbl_web
Compiling 1 file (.ex)
[info] Running RumblWeb.Endpoint with cowboy 2.9.0 at 0.0.0.0:4000 (http)
[info] Access RumblWeb.Endpoint at http://localhost:4000
[info] Application rumbl_web exited: RumblWeb.Application.start(:normal, []) returned an error: shutdown: failed to start child: RumblWeb.Presence
    ** (EXIT) shutdown: failed to start child: Phoenix.Presence.Tracker
        ** (EXIT) shutdown: failed to start child: RumblWeb.Presence_shard0
            ** (EXIT) an exception was raised:
                ** (ArgumentError) unknown registry: RumblWeb.PubSub
                    (elixir 1.11.4) lib/registry.ex:999: Registry.meta/2
                    (phoenix_pubsub 2.0.0) lib/phoenix/pubsub.ex:262: Phoenix.PubSub.node_name/1
                    (phoenix_pubsub 2.0.0) lib/phoenix/tracker/shard.ex:122: Phoenix.Tracker.Shard.init/1
                    (stdlib 3.14.2) gen_server.erl:417: :gen_server.init_it/2
                    (stdlib 3.14.2) gen_server.erl:385: :gen_server.init_it/6
                    (stdlib 3.14.2) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
** (Mix) Could not start application rumbl_web: RumblWeb.Application.start(:normal, []) returned an error: shutdown: failed to start child: RumblWeb.Presence
    ** (EXIT) shutdown: failed to start child: Phoenix.Presence.Tracker
        ** (EXIT) shutdown: failed to start child: RumblWeb.Presence_shard0
            ** (EXIT) an exception was raised:
                ** (ArgumentError) unknown registry: RumblWeb.PubSub
                    (elixir 1.11.4) lib/registry.ex:999: Registry.meta/2
                    (phoenix_pubsub 2.0.0) lib/phoenix/pubsub.ex:262: Phoenix.PubSub.node_name/1
                    (phoenix_pubsub 2.0.0) lib/phoenix/tracker/shard.ex:122: Phoenix.Tracker.Shard.init/1
                    (stdlib 3.14.2) gen_server.erl:417: :gen_server.init_it/2
                    (stdlib 3.14.2) gen_server.erl:385: :gen_server.init_it/6
                    (stdlib 3.14.2) proc_lib.erl:226: :proc_lib.init_p_do_apply/3

So that’s probably because the applications are started in the order they are defined in the children list (please correct me if I am wrong as I am a newbie in Elixir/Phoenix).

Hence if you just swap the places of PubSub and Presence like below everything will be fine.

    children = [
      # Start the Telemetry supervisor
      # RumblWeb.Telemetry,
      # Start the Endpoint (http/https)
      RumblWeb.Endpoint,
      {Phoenix.PubSub, name: RumblWeb.PubSub},
      RumblWeb.Presence,
      # Start a worker by calling: RumblWeb.Worker.start_link(arg)
      # {RumblWeb.Worker, arg}
    ]

This information might be helpful for newcomers like me.

3 Likes

Wow, thank you andreyuhai, very impressive.