0

I try to run my application on two nodes on one maschine: https://dockyard.com/blog/2016/01/28/running-elixir-and-phoenix-projects-on-a-cluster-of-nodes

I created config file:

[{kernel,
  [
    {sync_nodes_optional, ['n1@127.0.0.1', 'n2@127.0.0.1']},
    {sync_nodes_timeout, 10000}
  ]}
].

I run (from terminal 1):

 elixir --name n1@127.0.0.1 --erl "-config sys.config" -S mix phoenix.server

and then (from terminal 2):

elixir --name n2@127.0.0.1 --erl "-config sys.config" -S mix phoenix.server

and I receive:

** (Mix) Could not start application app: App.start(:normal, []) returned an error: shutdown: failed to start child: App.Endpoint
 ** (EXIT) shutdown: failed to start child: Phoenix.Endpoint.Server
  ** (EXIT) shutdown: failed to start child: {:ranch_listener_sup, App.Endpoint.HTTP}
   ** (EXIT) shutdown: failed to start child: :ranch_acceptors_sup
    ** (EXIT) {:listen_error, App.Endpoint.HTTP, :eaddrinuse}

What I'm doing wrong ?

Gazler
  • 83,029
  • 18
  • 279
  • 245

1 Answers1

0

You are getting this error because you are attempting to use the same port (4000 by default) for both nodes, which are running on the same machine.

Try doing:

PORT=4001 elixir --name n2@127.0.0.1 --erl "-config sys.config" -S mix phoenix.server

You will need to change dev.exs to support using an environment variable as a port:

config :my_app, MyApp.Endpoint,
  http: [port: String.to_integer(System.get_env("PORT") || "4000")],
Gazler
  • 83,029
  • 18
  • 279
  • 245
  • 1
    @Wulpo That's not possible. See http://stackoverflow.com/questions/1694144/can-two-applications-listen-to-the-same-port for more information. – Gazler Mar 02 '17 at 13:48
  • It is working, but my first intention is: Run 2 instance of application on 2 PC with one URL. When I change port, it will be "different" application. (distributing programming / computing) –  Mar 02 '17 at 13:48
  • 3
    @Wulpo If you are running on two difference physical machines then you can run them on the same port. – Gazler Mar 02 '17 at 13:49