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

Mix sometimes doesn't start all the applications #7930

Closed
TBK145 opened this Issue Jul 18, 2018 · 14 comments

Comments

Projects
None yet
6 participants
@TBK145
Copy link
Contributor

TBK145 commented Jul 18, 2018

Precheck

  • Do not use the issues tracker for help or support (try Elixir Forum, Stack Overflow, IRC, etc.)
  • For proposing a new feature, please start a discussion on the Elixir Core mailing list
  • For bugs, do a quick search and make sure the bug has not yet been reported
  • Finally, be nice and have fun!

Environment

  • Elixir & Erlang/OTP versions (elixir --version):
Erlang/OTP 21 [erts-10.0.2] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe]

IEx 1.7.0-rc.0 (1164784b8) (compiled with Erlang/OTP 21)

OTP 21.0.2, both built from source

  • Operating system:
$ uname -srvm
Linux 4.17.6-1-ARCH #1 SMP PREEMPT Wed Jul 11 19:14:29 UTC 2018 x86_64

Current behavior

We have an umbrella consisting of multiple apps with dependencies on each other.

When I do a clean compilation and try iex -S mix phx.server apps will fail to start because of applications not being started.

$ make run
iex  --sname thijs -S mix phx.server
Erlang/OTP 21 [erts-10.0.2] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe]

13:46:10.896 [info] pid=<0.42.0> module=application_controller function=info_exited/3 line=1935 Application summa_automate exited: SummaAutomate.Application.start(:normal, []) returned an error: shutdown: failed to start child: SummaAutomateWeb.Endpoint
    ** (EXIT) shutdown: failed to start child: Phoenix.Endpoint.Handler
        ** (EXIT) shutdown: failed to start child: {:ranch_listener_sup, SummaAutomateWeb.Endpoint.HTTP}
            ** (EXIT) exited in: :gen_server.call(:ranch_server, {:set_new_listener_opts, SummaAutomateWeb.Endpoint.HTTP, 16384, [env: [dispatch: [{:_, [], [{["phoenix", "live_reload", "socket", "longpoll"], [], Plug.Adapters.Cowboy.Handler, {Phoenix.Transports.LongPoll, {SummaAutomateWeb.Endpoint, Phoenix.LiveReloader.Socket, :longpoll}}}, {["phoenix", "live_reload", "socket", "websocket"], [], Phoenix.Endpoint.CowboyWebSocket, {Phoenix.Transports.WebSocket, {SummaAutomateWeb.Endpoint, Phoenix.LiveReloader.Socket, :websocket}}}, {["socket", "websocket"], [], Phoenix.Endpoint.CowboyWebSocket, {Phoenix.Transports.WebSocket, {SummaAutomateWeb.Endpoint, SummaAutomateWeb.UserSocket, :websocket}}}, {:_, [], Plug.Adapters.Cowboy.Handler, {SummaAutomateWeb.Endpoint, []}}]}]], onresponse: #Function<1.129103586/4 in Plug.Adapters.Cowboy.add_on_response/3>]})
                ** (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
** (Mix) Could not start application summa_automate: SummaAutomate.Application.start(:normal, []) returned an error: shutdown: failed to start child: SummaAutomateWeb.Endpoint
    ** (EXIT) shutdown: failed to start child: Phoenix.Endpoint.Handler
        ** (EXIT) shutdown: failed to start child: {:ranch_listener_sup, SummaAutomateWeb.Endpoint.HTTP}
            ** (EXIT) exited in: :gen_server.call(:ranch_server, {:set_new_listener_opts, SummaAutomateWeb.Endpoint.HTTP, 16384, [env: [dispatch: [{:_, [], [{["phoenix", "live_reload", "socket", "longpoll"], [], Plug.Adapters.Cowboy.Handler, {Phoenix.Transports.LongPoll, {SummaAutomateWeb.Endpoint, Phoenix.LiveReloader.Socket, :longpoll}}}, {["phoenix", "live_reload", "socket", "websocket"], [], Phoenix.Endpoint.CowboyWebSocket, {Phoenix.Transports.WebSocket, {SummaAutomateWeb.Endpoint, Phoenix.LiveReloader.Socket, :websocket}}}, {["socket", "websocket"], [], Phoenix.Endpoint.CowboyWebSocket, {Phoenix.Transports.WebSocket, {SummaAutomateWeb.Endpoint, SummaAutomateWeb.UserSocket, :websocket}}}, {:_, [], Plug.Adapters.Cowboy.Handler, {SummaAutomateWeb.Endpoint, []}}]}]], onresponse: #Function<1.129103586/4 in Plug.Adapters.Cowboy.add_on_response/3>]})
                ** (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

So I tried to start one of the apps separately and noticed that not everything was started.

$ cd apps/summa_api/
$ iex -S mix run
Erlang/OTP 21 [erts-10.0.2] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe]

13:46:21.611 [info] pid=<0.295.0> module=Summa.Api.Application function=start/2 line=24 Starting application Summa.Api.Application
Interactive Elixir (1.7.0-rc.0) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> Application.started_applications
[
  {:summa_api, 'summa_api', '1.8.0-dev'},
  {:logger, 'logger', '1.7.0-rc.0'},
  {:gettext, 'Internationalization and localization through gettext', '0.15.0'},
  {:phoenix,
   'Productive. Reliable. Fast. A productive web framework that\ndoes not compromise speed and maintainability.\n',
   '1.3.3'},
  {:phoenix_pubsub, 'Distributed PubSub and Presence platform\n', '1.0.2'},
  {:eex, 'eex', '1.7.0-rc.0'},
  {:poison, 'An incredibly fast, pure Elixir JSON library', '3.1.0'},
  {:plug,
   'A specification and conveniences for composable modules between web applications',
   '1.6.1'},
  {:mime, 'A MIME type module for Elixir', '1.3.0'},
  {:hex, 'hex', '0.18.1'},
  {:inets, 'INETS  CXC 138 49', '7.0'},
  {:ssl, 'Erlang/OTP SSL application', '9.0'},
  {:public_key, 'Public key infrastructure', '1.6.1'},
  {:asn1, 'The Erlang ASN1 compiler version 5.0.6', '5.0.6'},
  {:crypto, 'CRYPTO', '4.3'},
  {:mix, 'mix', '1.7.0-rc.0'},
  {:iex, 'iex', '1.7.0-rc.0'},
  {:elixir, 'elixir', '1.7.0-rc.0'},
  {:compiler, 'ERTS  CXC 138 10', '7.2.2'},
  {:stdlib, 'ERTS  CXC 138 10', '3.5.1'},
  {:kernel, 'ERTS  CXC 138 10', '6.0'}
]

When I switch back to Elixir 1.6.6 I get this output for the same command

$ kiex use 1.6.6
Using 1.6.6
$ iex -S mix run
Erlang/OTP 21 [erts-10.0.2] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe]

[compilation output...]

13:47:14.423 [info] pid=<0.2448.0> Setup running ...

13:47:14.429 [info] pid=<0.2448.0> Directories verified. Res = :ok

13:47:14.429 [info] pid=<0.2448.0> Setup finished processing hooks (Mode=:normal)...

13:47:14.622 [info] pid=<0.2463.0> [msg: 'Starting reporters with []\n', options: []]
13:47:14.708 [info] pid=<0.2488.0> module=Summa.Api.Application function=start/2 line=24 Starting application Summa.Api.Application
Interactive Elixir (1.6.6) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> Application.started_applications
[
  {:summa_api, 'summa_api', '1.8.0-dev'},
  {:phoenix_ecto, 'Integration between Phoenix & Ecto', '3.3.0'},
  {:ecto, 'A database wrapper and language integrated query for Elixir', 
   '2.2.10'},
  {:poolboy, 'A hunky Erlang worker pool factory', '1.5.1'},
  {:decimal, 'Arbitrary precision decimal arithmetic.', '1.5.0'},
  {:exometer_zabbix, 'A Zabbix reporter backend for exometer_core\n', '0.1.0'},
  {:exometer_influxdb, 'InfluxDB reporter for exometer', '0.5.8'},
  {:exometer_core, 'Code instrumentation and metrics collection package.',
   '1.5.2'},
  {:folsom, 'Erlang based metrics system', '0.8.7'},
  {:bear, 'A set of statistics functions for erlang', '0.8.7'},
  {:setup, 'Generic setup application for Erlang-based systems', '1.8.4'},
  {:hut,
   'helper library for making Erlang libraries logging framework agnostic',
   '1.2.0'},
  {:hackney, 'simple HTTP client', '1.10.1'},
  {:metrics, 'A generic interface to different metrics systems in Erlang.',
   '1.0.1'},
  {:ssl_verify_fun, [], '1.1.1'},
  {:certifi, 'An OTP library', '2.0.0'},
  {:mimerl, 'An OTP library', '1.0.2'},
  {:idna, 'A pure Erlang IDNA implementation', '5.1.0'},
  {:unicode_util_compat, 'unicode_util compatibility library for Erlang < 20',
   '0.3.1'},
  {:phoenix_live_reload, 'Provides live-reload functionality for Phoenix',
   '1.1.5'},
  {:file_system,
   'A file system change watcher wrapper based on [fs](https://github.com/synrc/fs)',
   '0.2.6'},
  {:phoenix_html,
   'Phoenix.HTML functions for working with HTML strings and templates',
   '2.11.2'},
  {:cowboy, 'Small, fast, modular HTTP server.', '1.1.2'},
  {:cowlib, 'Support library for manipulating Web protocols.', '1.0.2'},
  {:ranch, 'Socket acceptor pool for TCP protocols.', '1.3.2'},
  {:logger, 'logger', '1.6.6'},
  {:gettext, 'Internationalization and localization through gettext', '0.15.0'},
  {:phoenix,
   'Productive. Reliable. Fast. A productive web framework that\ndoes not compromise speed and maintainability.\n',
   '1.3.3'},
  {:phoenix_pubsub, 'Distributed PubSub and Presence platform\n', '1.0.2'},
  {:eex, 'eex', '1.6.6'},
  {:poison, 'An incredibly fast, pure Elixir JSON library', '3.1.0'},
  {:plug,
   'A specification and conveniences for composable modules between web applications',
   '1.6.1'},
  {:mime, 'A MIME type module for Elixir', '1.3.0'},
  {:hex, 'hex', '0.18.1'},
  {:inets, 'INETS  CXC 138 49', '7.0'},
  {:ssl, 'Erlang/OTP SSL application', '9.0'},
  {:public_key, 'Public key infrastructure', '1.6.1'},
  {:asn1, 'The Erlang ASN1 compiler version 5.0.6', '5.0.6'},
  {:crypto, 'CRYPTO', '4.3'},
  {:mix, 'mix', '1.6.6'},
  {:iex, 'iex', '1.6.6'},
  {:elixir, 'elixir', '1.6.6'},
  {:compiler, 'ERTS  CXC 138 10', '7.2.2'},
  {:stdlib, 'ERTS  CXC 138 10', '3.5.1'},
  {:kernel, 'ERTS  CXC 138 10', '6.0'}
]

This is the mix file

defmodule Summa.Api.Mixfile do
  use Mix.Project

  def project do
    [app: :summa_api,
     version: String.trim(File.read!("../../VERSION")),
     build_path: "../../_build",
     config_path: "../../config/config.exs",
     deps_path: "../../deps",
     lockfile: "../../mix.lock",
     elixir: "~> 1.4",
     elixirc_paths: elixirc_paths(Mix.env),
     compilers: [:phoenix, :gettext] ++ Mix.compilers,
     build_embedded: Mix.env == :prod,
     start_permanent: Mix.env == :prod,
     deps: deps()]
  end

  def application do
    [mod: {Summa.Api.Application, []},
     extra_applications: [:logger]]
  end

  defp elixirc_paths(:test), do: ["lib", "test/support"]
  defp elixirc_paths(_),     do: ["lib"]

  defp deps do
    [
      {:phoenix, "~> 1.3"},
      {:phoenix_pubsub, "~> 1.0"},
      {:phoenix_ecto, "~> 3.0"},
      {:phoenix_html, "~> 2.6"},
      {:phoenix_live_reload, "~> 1.0", only: :dev},
      {:gettext, "~> 0.11"},
      {:cowboy, "~> 1.0"},
      # Monitoring & Statistics
      {:exometer_influxdb, "~> 0.5"},
      {:exometer_zabbix, "~> 0.1"},
      # Auto discovery of erlang nodes
      {:peerage, "~> 1.0", runtime: conditional_peerage()}
    ]
  end

  defp conditional_peerage() do
    cond do
      System.get_env("TOTAL_NODES") != nil -> true
      Mix.env == :prod -> true
      true -> false
    end
  end
end

Now when I switch back to 1.7.0-rc.0, it will start all the applications.

I checked the .app files and noticed this difference

summa_api.app on 1.6.6

{application,summa_api,
             [{applications,[kernel,stdlib,elixir,logger,gettext,
                             phoenix_pubsub,cowboy,phoenix_html,phoenix,
                             phoenix_live_reload,exometer_influxdb,
                             exometer_zabbix,phoenix_ecto]},
              {description,"summa_api"},
              {modules,['Elixir.Summa.Api.Application',
                        'Elixir.Summa.Api.Auth.Error',
                        'Elixir.Summa.Api.Channel',
                        'Elixir.Summa.Api.Channel.Diff',
                        'Elixir.Summa.Api.Channel.Version',
                        'Elixir.Summa.Api.Presence','Elixir.Summa.Api.PubSub',
                        'Elixir.Summa.Api.Registry',
                        'Elixir.Summa.Api.Service',
                        'Elixir.Summa.Api.Service.File']},
              {registered,[]},
              {vsn,"1.8.0-dev"},
              {mod,{'Elixir.Summa.Api.Application',[]}},
              {extra_applications,[logger]}]}.

summa_api.app on 1.7.0-rc.0

{application,summa_api,
             [{applications,[kernel,stdlib,elixir,logger]},
              {description,"summa_api"},
              {modules,['Elixir.Summa.Api.Application',
                        'Elixir.Summa.Api.Auth.Error',
                        'Elixir.Summa.Api.Channel',
                        'Elixir.Summa.Api.Channel.Diff',
                        'Elixir.Summa.Api.Channel.Version',
                        'Elixir.Summa.Api.Presence','Elixir.Summa.Api.PubSub',
                        'Elixir.Summa.Api.Registry',
                        'Elixir.Summa.Api.Service',
                        'Elixir.Summa.Api.Service.File']},
              {registered,[]},
              {vsn,"1.8.0-dev"},
              {mod,{'Elixir.Summa.Api.Application',[]}}]}.

I couldn't find anything about this in the changelog, so I'm thinking this is a regression.

@josevalim

This comment has been minimized.

Copy link
Member

josevalim commented Jul 18, 2018

Thank you, it is a bug. A fix should be out soon!

josevalim added a commit that referenced this issue Jul 18, 2018

@josevalim

This comment has been minimized.

Copy link
Member

josevalim commented Jul 18, 2018

Closing in favor of #7931.

@josevalim josevalim closed this Jul 18, 2018

josevalim added a commit that referenced this issue Jul 18, 2018

josevalim added a commit that referenced this issue Jul 18, 2018

Properly populate top_level field of deps (#7931)
Closes #7930

Signed-off-by: José Valim <jose.valim@plataformatec.com.br>
@Adzz

This comment has been minimized.

Copy link

Adzz commented Jan 23, 2019

I seem to be seeing this behaviour again when updating to 1.8.0:

screenshot 2019-01-23 at 11 11 59

@josevalim

This comment has been minimized.

Copy link
Member

josevalim commented Jan 23, 2019

@Adzz can you please provide a minimal application that reproduces the error? Something like mix new example and you update the mix.exs file with the relevant dependencies. Thank you!

@Math3v

This comment has been minimized.

Copy link

Math3v commented Jan 25, 2019

@josevalim Actually, I'm having the very same error. I generated new Phoenix app and added Wallaby with sample integration spec.

Here is my repo https://github.com/Math3v/personal_site

@Math3v

This comment has been minimized.

Copy link

Math3v commented Jan 25, 2019

Maybe this is more helpful?

➜  personal_site git:(a0a09dd) mix ecto.reset
The database for PersonalSite.Repo has been dropped
The database for PersonalSite.Repo has been created

21:30:15.133 [info]  Application telemetry exited: :stopped
** (MatchError) no match of right hand side value: {:error, {:poison, {'no such file or directory', 'poison.app'}}}
    (ecto_sql) lib/mix/ecto_sql.ex:9: Mix.EctoSQL.ensure_started/2
    (ecto_sql) lib/mix/tasks/ecto.migrate.ex:103: anonymous fn/4 in Mix.Tasks.Ecto.Migrate.run/2
    (elixir) lib/enum.ex:769: Enum."-each/2-lists^foreach/1-0-"/2
    (elixir) lib/enum.ex:769: Enum.each/2
    (mix) lib/mix/task.ex:331: Mix.Task.run_task/3
    (mix) lib/mix/task.ex:365: Mix.Task.run_alias/3
    (mix) lib/mix/task.ex:292: Mix.Task.run/2
    (mix) lib/mix/task.ex:365: Mix.Task.run_alias/3
    (mix) lib/mix/task.ex:292: Mix.Task.run/2
    (mix) lib/mix/cli.ex:79: Mix.CLI.run_task/2
    (elixir) lib/code.ex:767: Code.require_file/2
@Adzz

This comment has been minimized.

Copy link

Adzz commented Jan 25, 2019

I am trying to create a minimal test case now, will update when i do

@hectorsq

This comment has been minimized.

Copy link

hectorsq commented Jan 27, 2019

@josevalim I have a mimimal app here https://github.com/hectorsq/mx-test

It fails after adding poison to dependecies.

It is an umbrella project. If you run mix phx.server at the top folder everything works fine. If you run mix phx.serverat apps/mx_web the following error appears.

** (Mix) Could not start application poison: could not find application file: poison.app

@josevalim

This comment has been minimized.

Copy link
Member

josevalim commented Jan 28, 2019

@hectorsq That's because you are listing poison at the root. :) Look at what these comments say:

https://github.com/hectorsq/mx-test/blob/master/mix.exs#L12-L14

Anything at the root will not be available to children.

@josevalim

This comment has been minimized.

Copy link
Member

josevalim commented Jan 28, 2019

@Math3v your app has a different error that looks like this (at least for me on v1.8):

** (MatchError) no match of right hand side value: {:error, {:wallaby, {:bad_return, {{Wallaby, :start, [:normal, []]}, {:EXIT, {%Wallaby.DependencyError{message: "Wallaby can't find phantomjs. Make sure you have phantomjs installed\nand included in your path, or that your config :wallaby, :phantomjs\nsetting points to a valid phantomjs executable.\n"}, [{Wallaby, :start, 2, [file: 'lib/wallaby.ex', line: 29]}, {:application_master, :start_it_old, 4, [file: 'application_master.erl', line: 277]}]}}}}}} 

The error is not nicely formatted because wallaby is being started dynamically. If you remove runtime: false from mix.exs, you will see this:

** (Mix) Could not start application wallaby: exited in: Wallaby.start(:normal, [])
** (EXIT) an exception was raised:
** (Wallaby.DependencyError) Wallaby can't find phantomjs. Make sure you have phantomjs installed
and included in your path, or that your config :wallaby, :phantomjs
setting points to a valid phantomjs executable.

       (wallaby) lib/wallaby.ex:29: Wallaby.start/2
       (kernel) application_master.erl:277: :application_master.start_it_old/4

With the relevant bits being:

Wallaby can't find phantomjs. Make sure you have phantomjs installed\nand included in your path, or that your config :wallaby, :phantomjs\nsetting points to a valid phantomjs executable

@hectorsq

This comment has been minimized.

Copy link

hectorsq commented Jan 28, 2019

@josevalim, Thanks! Seems that my goal in life is to make you waste time.

I fixed the project at https://github.com/hectorsq/mx-test and added another web app (br_web) under the umbrella. Now I have two web apps, mx_web depends on poison, br_web does not depend on poison.

If you run mix phx.server at the root both web apps start.
If you run mix phx.server at mx_web the app starts.
However if I run mix phx.server at br_web I get the error.

** (Mix) Could not start application poison: could not find application file: poison.app

Am I missing something?

@Wijnand

This comment has been minimized.

Copy link

Wijnand commented Jan 29, 2019

This last case is what we are seeing as well. Elixir 1.7 is just fine. Starting an individual app in an umbrella can fail because of dependencies it does not have, but other apps do have.

@josevalim josevalim reopened this Jan 29, 2019

@josevalim josevalim closed this in 9de51f8 Jan 29, 2019

josevalim added a commit that referenced this issue Jan 29, 2019

Revert "Include optional dependencies in extra_applications (#8263)"
Unfortunately adding optional dependencies doesn't work for umbrella
apps where each app has a different optional dependency. For example,
Ecto 3.0 has both jason and poison as optional deps. Imagine the two
umbrella children below:

    foo
      * ecto
      * jason

    bar
      * ecto
      * poison
      * jason

Because ecto is shared with both, Ecto will include both poison and
jason, which makes`foo` fail to boot when running in isolation.

Closes #7930.
@josevalim

This comment has been minimized.

Copy link
Member

josevalim commented Jan 29, 2019

Beautiful, fixed in master and v1.8. I plan to release v1.8.1 tomorrow.

@hectorsq

This comment has been minimized.

Copy link

hectorsq commented Jan 30, 2019

Great! No problem now in Elixir 1.8.1

Hanspagh added a commit to Hanspagh/elixir that referenced this issue Mar 19, 2019

Revert "Include optional dependencies in extra_applications (elixir-l…
…ang#8263)"

Unfortunately adding optional dependencies doesn't work for umbrella
apps where each app has a different optional dependency. For example,
Ecto 3.0 has both jason and poison as optional deps. Imagine the two
umbrella children below:

    foo
      * ecto
      * jason

    bar
      * ecto
      * poison
      * jason

Because ecto is shared with both, Ecto will include both poison and
jason, which makes`foo` fail to boot when running in isolation.

Closes elixir-lang#7930.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.