Application start up fail cause by unclear reason: failed to start child: ChatWeb.Endpoint

I am getting an error when I try to start my server.
below is the error stack just return, could someone just happen to know what cause this problem.
I have tried to upgrade the deps version, it didnt seem to work.

** (Mix) Could not start application chat: Chat.Application.start(:normal, []) returned an error: shutdown: failed to start child: ChatWeb.Endpoint
    ** (EXIT) shutdown: failed to start child: {:ranch_listener_sup, ChatWeb.Endpoint.HTTP}
        ** (EXIT) exited in: :gen_server.call(:ranch_server, {:set_new_listener_opts, ChatWeb.Endpoint.HTTP, 16384, %{max_connections: 16384, num_acceptors: 100, socket_opts: [port: 4000]}, %{env: %{dispatch: [{:_, [], [{:_, [], Phoenix.Endpoint.Cowboy2Handler, {ChatWeb.Endpoint, []}}]}]}, stream_handlers: [:cowboy_telemetry_h, :cowboy_stream_h]}, [ChatWeb.Endpoint.HTTP, :ranch_tcp, %{max_connections: 16384, num_acceptors: 100, socket_opts: [port: 4000]}, :cowboy_clear, %{env: %{dispatch: [{:_, [], [{:_, [], Phoenix.Endpoint.Cowboy2Handler, {ChatWeb.Endpoint, []}}]}]}, stream_handlers: [:cowboy_telemetry_h, :cowboy_stream_h]}]})
            ** (EXIT) no process: the process is not alive or there's no process currently associated with the given name, possibly because its application isn't started

Here is my mix.exs
not sure whether i just configure in the wrong way or not.

defmodule Chat.Mixfile do
  use Mix.Project

  def project do
    [
      app: :chat,
      version: "0.0.1",
      elixir: "~> 1.4",
      elixirc_paths: elixirc_paths(Mix.env),
      compilers: [:phoenix, :gettext] ++ Mix.compilers,
      start_permanent: Mix.env == :prod,
      aliases: aliases(),
      deps: deps()
    ]
  end

  
  def application do
    [
      mod: {Chat.Application, []},
      applications: [:phoenix, :phoenix_pubsub, :phoenix_ecto, :postgrex, :coherence],
      extra_applications: [:logger, :runtime_tools]
    ]
  end

  defp elixirc_paths(:test), do: ["lib", "test/support"]
  defp elixirc_paths(_),     do: ["lib"]
  defp deps do
    [
      {:phoenix, "~> 1.5.7"},
      {:phoenix_pubsub, "~> 2.0"},
      {:phoenix_ecto, "~> 3.2"},
      {:postgrex, ">= 0.0.0"},
      {:phoenix_html, "~> 2.10"},
      {:phoenix_live_reload, "~> 1.0", only: :dev},
      {:gettext, "~> 0.11"},
      {:cowboy, "~> 2.0"},
      {:plug_cowboy, "~> 2.0"},
      {:coherence, "~> 0.3"},
      {:poison, "~> 3.1"}
    ]
  end

  defp aliases do
    [
      "ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"],
      "ecto.reset": ["ecto.drop", "ecto.setup"],
      "test": ["ecto.create --quiet", "ecto.migrate", "test"]
    ]
  end
end

The problem is the applications key - if it’s not supplied at all, you get the built-in behavior where all of the applications listed in deps are started automatically.

If you supply a value, the runtime assumes you know what you are doing and ONLY starts those applications - so things like ranch which aren’t listed don’t get started, and you get the error you’re seeing.

A good writeup about the difference between applications and extra_applications from a while back.

4 Likes

Thanks for your kindly explanation,that’s just what it is!