My app crashes at the start

This line in error stack trace is what bothers me

(phoenix) lib/phoenix/endpoint/handler.ex:33: anonymous fn/5 in Phoenix.Endpoint.Handler.init/1

That do not exists in phoenix if I’m not wrong. Could you check in mix.lock what commit mix checked out for you?

2 Likes

I’v checked older tags on github, this Phoenix.Endpoint.Handler is part of 1.3 stuff. Try to delete deps folder and do deps.get again. I think it somehow reads old version stuff and mixing it with code that is checkout from git. Also check what is in mix.lock since some deps could be pulling older version.

1 Like

rm mix.lock && rm -rf _build/ && mix deps.get --all

1 Like

Never delete _build without deleting deps and vice versa…

2 Likes

This doesn’t work either

[
  {:phoenix, "~> 1.4-rc.2", override: true},
  # {:cowboy, "~> 2.4"},
  {:plug_cowboy, "~> 2.0"},

_build and deps directories were deleted

I really think we need an SSCCE git repo that we can clone and try ourselves at this point? Really sounds like some kind of wrong setup issue or so…

2 Likes

This should work My app crashes at the start ?

With the bog standard phoenix 1.4-rc2 setup using cowboy2 it runs without issue, this is the mix.exs file:

defmodule TestFourteenBug.MixProject do
  use Mix.Project

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

  # Configuration for the OTP application.
  #
  # Type `mix help compile.app` for more information.
  def application do
    [
      mod: {TestFourteenBug.Application, []},
      extra_applications: [:logger, :runtime_tools]
    ]
  end

  # Specifies which paths to compile per environment.
  defp elixirc_paths(:test), do: ["lib", "test/support"]
  defp elixirc_paths(_), do: ["lib"]

  # Specifies your project dependencies.
  #
  # Type `mix help deps` for examples and options.
  defp deps do
    [
      {:phoenix, "~> 1.4.0-rc.2"},
      {:phoenix_pubsub, "~> 1.1"},
      {:phoenix_ecto, "~> 3.5"},
      {:ecto, "~> 3.0-rc", override: true},
      {:ecto_sql, "~> 3.0-rc", override: true},
      {:postgrex, ">= 0.0.0-rc"},
      {:phoenix_html, "~> 2.11"},
      {:phoenix_live_reload, "~> 1.2-rc", only: :dev},
      {:gettext, "~> 0.11"},
      {:jason, "~> 1.0"},
      {:plug_cowboy, "~> 2.0"}
    ]
  end

  # Aliases are shortcuts or tasks specific to the current project.
  # For example, to create, migrate and run the seeds file at once:
  #
  #     $ mix ecto.setup
  #
  # See the documentation for `Mix` for more info on aliases.
  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

And the mix.lock is:

%{
  "connection": {:hex, :connection, "1.0.4", "a1cae72211f0eef17705aaededacac3eb30e6625b04a6117c1b2db6ace7d5976", [:mix], [], "hexpm"},
  "cowboy": {:hex, :cowboy, "2.5.0", "4ef3ae066ee10fe01ea3272edc8f024347a0d3eb95f6fbb9aed556dacbfc1337", [:rebar3], [{:cowlib, "~> 2.6.0", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "~> 1.6.2", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm"},
  "cowlib": {:hex, :cowlib, "2.6.0", "8aa629f81a0fc189f261dc98a42243fa842625feea3c7ec56c48f4ccdb55490f", [:rebar3], [], "hexpm"},
  "db_connection": {:hex, :db_connection, "2.0.0-rc.0", "f6960e86b5e524468ec16fb7277e509c784de565ac520213a1813ad2bf7d802f", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}], "hexpm"},
  "decimal": {:hex, :decimal, "1.5.0", "b0433a36d0e2430e3d50291b1c65f53c37d56f83665b43d79963684865beab68", [:mix], [], "hexpm"},
  "ecto": {:hex, :ecto, "3.0.0-rc.1", "c966a270b289739d6895f61bee339065a3075d1df34ddd369d400cf0c936fd6c", [:mix], [{:decimal, "~> 1.5", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: true]}], "hexpm"},
  "ecto_sql": {:hex, :ecto_sql, "3.0.0-rc.0", "a61da743812a47174e8b79dbe6aa7d4a9f7e6dbf8c90cfd7015f3767738b37ba", [:mix], [{:db_connection, "~> 2.0-rc.0", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.0.0-rc.1", [hex: :ecto, repo: "hexpm", optional: false]}, {:mariaex, "~> 0.9.0-rc.0", [hex: :mariaex, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.14.0-rc.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.2.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm"},
  "file_system": {:hex, :file_system, "0.2.6", "fd4dc3af89b9ab1dc8ccbcc214a0e60c41f34be251d9307920748a14bf41f1d3", [:mix], [], "hexpm"},
  "gettext": {:hex, :gettext, "0.16.0", "4a7e90408cef5f1bf57c5a39e2db8c372a906031cc9b1466e963101cb927dafc", [:mix], [], "hexpm"},
  "jason": {:hex, :jason, "1.1.2", "b03dedea67a99223a2eaf9f1264ce37154564de899fd3d8b9a21b1a6fd64afe7", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm"},
  "mime": {:hex, :mime, "1.3.0", "5e8d45a39e95c650900d03f897fbf99ae04f60ab1daa4a34c7a20a5151b7a5fe", [:mix], [], "hexpm"},
  "phoenix": {:hex, :phoenix, "1.4.0-rc.2", "5f9d03090a8ea9d03404a5b8610c4b9f43471a45d31cb4282f6789cdaead6f59", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 1.1", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 1.0 or ~> 2.0", [hex: :plug_cowboy, repo: "hexpm", optional: true]}], "hexpm"},
  "phoenix_ecto": {:hex, :phoenix_ecto, "3.5.0", "f72ec302589988698c096da7e8647e917fa2bb2f861c0c3739fc9d95708bacec", [:mix], [{:ecto, "~> 2.2 or ~> 3.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.9", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"},
  "phoenix_html": {:hex, :phoenix_html, "2.12.0", "1fb3c2e48b4b66d75564d8d63df6d53655469216d6b553e7e14ced2b46f97622", [:mix], [{:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"},
  "phoenix_live_reload": {:hex, :phoenix_live_reload, "1.2.0-rc.0", "e4876fe249fdfbcca372a2c8d512a7c67d893d7a4f1bb66597050aa4d5001a69", [:mix], [{:file_system, "~> 0.2.1 or ~> 0.3", [hex: :file_system, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.4-rc", [hex: :phoenix, repo: "hexpm", optional: false]}], "hexpm"},
  "phoenix_pubsub": {:hex, :phoenix_pubsub, "1.1.1", "6668d787e602981f24f17a5fbb69cc98f8ab085114ebfac6cc36e10a90c8e93c", [:mix], [], "hexpm"},
  "plug": {:hex, :plug, "1.7.1", "8516d565fb84a6a8b2ca722e74e2cd25ca0fc9d64f364ec9dbec09d33eb78ccd", [:mix], [{:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}], "hexpm"},
  "plug_cowboy": {:hex, :plug_cowboy, "2.0.0", "ab0c92728f2ba43c544cce85f0f220d8d30fc0c90eaa1e6203683ab039655062", [:mix], [{:cowboy, "~> 2.5", [hex: :cowboy, repo: "hexpm", optional: false]}, {:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"},
  "plug_crypto": {:hex, :plug_crypto, "1.0.0", "18e49317d3fa343f24620ed22795ec29d4a5e602d52d1513ccea0b07d8ea7d4d", [:mix], [], "hexpm"},
  "postgrex": {:hex, :postgrex, "0.14.0-rc.1", "a88cbeab25c5f3fc505fc6590bd30877a5acf11b448aedb23b41cbc063824ceb", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 2.0-rc.0", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm"},
  "ranch": {:hex, :ranch, "1.6.2", "6db93c78f411ee033dbb18ba8234c5574883acb9a75af0fb90a9b82ea46afa00", [:rebar3], [], "hexpm"},
  "telemetry": {:hex, :telemetry, "0.2.0", "5b40caa3efe4deb30fb12d7cd8ed4f556f6d6bd15c374c2366772161311ce377", [:mix], [], "hexpm"},
}

And that includes the two dependency lines you show as using for phoenix and plug_cowboy, so I really need an SSCCE from you to reproduce it as I can’t seem to be able to… ^.^;

2 Likes

Try to use Elixir 1.7

I’m pretty sure @OvermindDL1 does already, as he usually is on most recent stable usually, if not on master…

Also there is no 1.7. If you consider your elixir version to be the fault, then please provide the full version and which OTP it was built on, such that we can reproduce your environment as close as possible. Also, as you blame the elixir version, have you upgraded or downgraded it? Does the problem go away then? If not, how come blaming the elixir version?

Also you have been asked for a SSCCE, if you had provided it, you probably had some more input and directions for solving your problem.

1 Like

Show your “config/” directory

╰─➤  asdf current elixir
1.7.3-otp-21

Yep, though now on 1.7.4-otp-21 on that server. ^.^

Entirely stock/standard, everything is unchanged from the standard phx_new setup:

╰─➤  find config -type f
config/prod.secret.exs
config/config.exs
config/test.exs
config/dev.exs
config/prod.exs

Here are the contents of the two files that matter (since I ran in standard dev mode):

config.exs:

# This file is responsible for configuring your application
# and its dependencies with the aid of the Mix.Config module.
#
# This configuration file is loaded before any dependency and
# is restricted to this project.

# General application configuration
use Mix.Config

config :test_fourteen_bug,
  ecto_repos: [TestFourteenBug.Repo]

# Configures the endpoint
config :test_fourteen_bug, TestFourteenBugWeb.Endpoint,
  url: [host: "localhost"],
  secret_key_base: "m37BfboSxMkut6vHe/N8Qhns2qZZ48knfMJeIHjHdUYPFn5yXzIYfweaLBDh++X/",
  render_errors: [view: TestFourteenBugWeb.ErrorView, accepts: ~w(html json)],
  pubsub: [name: TestFourteenBug.PubSub, adapter: Phoenix.PubSub.PG2]

# Configures Elixir's Logger
config :logger, :console,
  format: "$time $metadata[$level] $message\n",
  metadata: [:request_id]

# Use Jason for JSON parsing in Phoenix
config :phoenix, :json_library, Jason

# Import environment specific config. This must remain at the bottom
# of this file so it overrides the configuration defined above.
import_config "#{Mix.env()}.exs"

dev.exs:

use Mix.Config

# For development, we disable any cache and enable
# debugging and code reloading.
#
# The watchers configuration can be used to run external
# watchers to your application. For example, we use it
# with webpack to recompile .js and .css sources.
config :test_fourteen_bug, TestFourteenBugWeb.Endpoint,
  http: [port: 4000],
  debug_errors: true,
  code_reloader: true,
  check_origin: false,
  watchers: [
    node: [
      "node_modules/webpack/bin/webpack.js",
      "--mode",
      "development",
      "--watch-stdin",
      cd: Path.expand("../assets", __DIR__)
    ]
  ]

# ## SSL Support
#
# In order to use HTTPS in development, a self-signed
# certificate can be generated by running the following
# Mix task:
#
#     mix phx.gen.cert
#
# Note that this task requires Erlang/OTP 20 or later.
# Run `mix help phx.gen.cert` for more information.
#
# The `http:` config above can be replaced with:
#
#     https: [
#       port: 4001,
#       cipher_suite: :strong,
#       keyfile: "priv/cert/selfsigned_key.pem",
#       certfile: "priv/cert/selfsigned.pem"
#     ],
#
# If desired, both `http:` and `https:` keys can be
# configured to run both http and https servers on
# different ports.

# Watch static and templates for browser reloading.
config :test_fourteen_bug, TestFourteenBugWeb.Endpoint,
  live_reload: [
    patterns: [
      ~r{priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$},
      ~r{priv/gettext/.*(po)$},
      ~r{lib/test_fourteen_bug_web/views/.*(ex)$},
      ~r{lib/test_fourteen_bug_web/templates/.*(eex)$}
    ]
  ]

# Do not include metadata nor timestamps in development logs
config :logger, :console, format: "[$level] $message\n"

# Set a higher stacktrace during development. Avoid configuring such
# in production as building large stacktraces may be expensive.
config :phoenix, :stacktrace_depth, 20

# Initialize plugs at runtime for faster development compilation
config :phoenix, :plug_init_mode, :runtime

# Configure your database
config :test_fourteen_bug, TestFourteenBug.Repo,
  username: "postgres",
  password: "postgres",
  database: "test_fourteen_bug_dev",
  hostname: "localhost",
  pool_size: 10

All standard from a normal phx_new call.

We really really need that SSCCE so we can just git clone ... it and run it ourselves.

Here is another observable. With Phoenix 1.3.3, on Windows, mix phx.new some_name. Set up a dev.exs login. Compile. Mix phx.server. The error happens. It wasn’t happening evening before.

This started last evening EST for me.

Doesn’t have support for Cowboy2 nor does it have any Cowboy2 code, so would need an SSCCE for that too.

As we are trying to debug his app and not yours, I’m not sure if I had answered the question for the config…

1 Like

Yep, but we haven’t got an SSCCE yet so the best we can do is compare our working versions and see how theirs is different. ^.^

We really need an SSCCE… >.>

Please verify the assumption that nothing changed in 1.3 when doing a phx.new. The errors that I was receiving are very similar to the errors described above.

The 1.3 installer had not changed in a very long time.

Regardless of Phoenix version, if you are using Plug 1.7, then you will require {:plug_cowboy, "~> 1.0"} for cowboy to work.

If you are using Phoenix 1.4, then you can use {:plug_cowboy, "~> 2.0"} or {:plug_cowboy, "~> 1.0"}.

You should be prompted about this when the application starts:

warning: please add the following dependency to your mix.exs:

    {:plug_cowboy, "~> 1.0"}

This dependency is required by Plug.Adapters.Cowboy
which you may be using directly or indirectly.
Note you no longer need to depend on :cowboy directly.


[info] Application yolo123 exited: Yolo123.Application.start(:normal, []) returned an error: shutdown: failed to start child: Yolo123Web.Endpoint
    ** (EXIT) shutdown: failed to start child: Phoenix.Endpoint.Handler
        ** (EXIT) {%RuntimeError{message: "no plug_cowboy adapter"}, []}
** (Mix) Could not start application yolo123: Yolo123.Application.start(:normal, []) returned an error: shutdown: failed to start child: Yolo123Web.Endpoint
    ** (EXIT) shutdown: failed to start child: Phoenix.Endpoint.Handler
        ** (EXIT) {%RuntimeError{message: "no plug_cowboy adapter"}, []}
3 Likes

I’ve figured out a work around for the Windows 1.3.4 fresh phx.new. Here is the error that I see upon phx.new, …follow proper steps for a Getting Started app …

{:plug_cowboy, "~> 1.0"}

This dependency is required by Plug.Adapters.Cowboy
which you may be using directly or indirectly.
Note you no longer need to depend on :cowboy directly.

[info] Application crash_r2 exited: CrashR2.Application.start(:normal, []) returned an error: shutdown: failed to start child: CrashR2Web.Endpoint
** (EXIT) shutdown: failed to start child: Phoenix.Endpoint.Handler
** (EXIT) “plug_cowboy dependency missing”
** (Mix) Could not start application crash_r2: CrashR2.Application.start(:normal, []) returned an error: shutdown: failed to start child: CrashR2Web.Endpoint
** (EXIT) shutdown: failed to start child: Phoenix.Endpoint.Handler
** (EXIT) “plug_cowboy dependency missing”

The workaround that allows the application to start:

when performing mix phx.new

The mix.lock file pulls in:
“plug”: {:hex, :plug, “1.7.1”, “8516d565fb84a6a8b2ca722e74e2cd25ca0fc9d64f364ec9dbec09d33eb78ccd”, [:mix], [{:mime, “~> 1.0”, [hex: :mime, repo: “hexpm”, optional: false]}, {:plug_crypto, “~> 1.0”, [hex: :plug_crypto, repo: “hexpm”, optional: false]}], “hexpm”},

When the above is replaced with:
“plug”: {:hex, :plug, “1.6.3”, “43088304337b9e8b8bd22a0383ca2f633519697e4c11889285538148f42cbc5e”, [:mix], [{:cowboy, “~> 1.0.1 or ~> 1.1 or ~> 2.4”, [hex: :cowboy, repo: “hexpm”, optional: true]}, {:mime, “~> 1.0”, [hex: :mime, repo: “hexpm”, optional: false]}], “hexpm”},

The server will start.

This situation happens on a fresh mix phx.new with the latest Phoenix 1.3.4 on a fresh Windows 10 machine. Is plug 1.7.1 correct for a 1.3.4 Phoenix?