Phoenix: Phoenix 1.3.0-rc3 mix phx.server hangs with MIX_ENV=prod

Created on 24 Jul 2017  路  10Comments  路  Source: phoenixframework/phoenix

Environment

  • Elixir version (elixir -v): 1.4.4
  • Phoenix version (mix deps): 1.3.0-rc3
  • NodeJS version (node -v): 7.7.4
  • NPM version (npm -v): 4.1.2
  • Operating system: MacOS Sierra 10.12.4

Expected behavior

MIX_ENV=prod mix phx.server starts the server.

Actual behavior

MIX_ENV=prod mix phx.server hangs and never starts up.

Reproduced in current project locally and on production (Heroku), as well as a brand new project.

open for guidance

Most helpful comment

It is actually a backwards incompatible change between the release candidates. This configuration is no longer supported: https://github.com/johnmosesman/phoenix_1.3.0-rc3_bug/blob/master/config/prod.exs#L17

Instead of on_init, do this in your config:

load_from_system_env: true,

and then in your endpoint:

@doc """
  Callback invoked for dynamically configuring the endpoint.

  It receives the endpoint configuration and checks if
  configuration should be loaded from the system environment.
  """
  def init(_key, config) do
    if config[:load_from_system_env] do
      port = System.get_env("PORT") || raise "expected the PORT environment variable to be set"
      {:ok, Keyword.put(config, :http, [:inet6, port: port])}
    else
      {:ok, config}
    end
  end

@chrismccord can you please make sure this is in the release announcements?

All 10 comments

Seconding - I paired on this. Seems like something broke since the last rc.

We couldn't see anything in the logs that told us why it was hanging; we just saw that it timed out before binding to the port and was restarted (this is on Heroku).

It is actually a backwards incompatible change between the release candidates. This configuration is no longer supported: https://github.com/johnmosesman/phoenix_1.3.0-rc3_bug/blob/master/config/prod.exs#L17

Instead of on_init, do this in your config:

load_from_system_env: true,

and then in your endpoint:

@doc """
  Callback invoked for dynamically configuring the endpoint.

  It receives the endpoint configuration and checks if
  configuration should be loaded from the system environment.
  """
  def init(_key, config) do
    if config[:load_from_system_env] do
      port = System.get_env("PORT") || raise "expected the PORT environment variable to be set"
      {:ok, Keyword.put(config, :http, [:inet6, port: port])}
    else
      {:ok, config}
    end
  end

@chrismccord can you please make sure this is in the release announcements?

Let's leave this open for guidance.

Done

@chrismccord @josevalim thanks!

Is this something that could be changed in mix phx.new to set it up correctly?

rc.3 does not generate that code. So you either have two archives installed or you generated the app using rc.2 and Hex picked up rc.3. :) I have also added a warning to master that will hopefully aid future migrations.

Is this issue still relevant now that 1.3.0 has been released? to help you guys clean the list of issues :)

Good call, I think enough time has passed since we left this open for guidance that we can close this. :)

Yes, we were able to fix this issue using Jose's suggestion. Thanks!

Was this page helpful?
0 / 5 - 0 ratings