2
votes

Running into an odd error with Phoenix on Heroku, where it doesn't seem to bind to the port properly.

Running into a situation where phoenix is not binding to $PORT. Heroku's log:

2016-03-25T22:22:54.716907+00:00 heroku[web.1]: State changed from crashed to starting

2016-03-25T22:23:03.156662+00:00 heroku[web.1]: Starting process with command mix phoenix.server

2016-03-25T22:23:07.985368+00:00 app[web.1]: [info] Running AppName.Endpoint with Cowboy using http on port 4000

2016-03-25T22:23:10.027386+00:00 app[web.1]: 25 Mar 22:23:10 - info: compiled 5 files into 2 files, copied 3 in 1.5 sec

2016-03-25T22:24:03.442109+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch

2016-03-25T22:24:03.442109+00:00 heroku[web.1]: Stopping process with SIGKILL

2016-03-25T22:24:04.195291+00:00 heroku[web.1]: Process exited with status 137

2016-03-25T22:24:04.211713+00:00 heroku[web.1]: State changed from starting to crashed

My prod.exs:

config :appname, AppName.Endpoint,
  http: [port: {:system, "PORT"}],
  url: [scheme: "https", host: "AppName.herokuapp.com", port: 443],
  force_ssl: [rewrite_on: [:x_forwarded_proto]],
  cache_static_manifest: "priv/static/manifest.json",
  secret_key_base: System.get_env("SECRET_KEY_BASE")

It looks like it's going to port 4000 instead of whatever port Heroku wants, and I'm not sure why.

1

1 Answers

2
votes

The fix is twofold:

  1. to use the phoenix buildpack config and export the PORT as well, like so: config_vars_to_export=(DATABASE_URL PORT)
  2. Avoid changing the MIX_ENV without recompiling the app, as that behavior is unsupported, as explained here.