wojtekmach / acme_bank

An example ☂ project
MIT License
756 stars 103 forks source link

Error when trying to run two instances of the app from MasterProxy #10

Closed enilsen16 closed 7 years ago

enilsen16 commented 7 years ago
[error] Failed to start Ranch listener MasterProxy.Plug.HTTP in :ranch_tcp:listen([port: 3333]) for reason :eaddrinuse (address already in use)

When I run mix run --no-halt and iex -S mix inside of /apps/master_proxy, I get the error above. I thought about trying to have something like this:

if :erlang.whereis(MasterProxy.Plug.HTTP) == :undefined, do: [Plug.Adapters.Cowboy.child_spec(:http, MasterProxy.Plug, [], [port: port])], else: []

Doesn't seem to work though. Any thoughts?

wojtekmach commented 7 years ago

I guess this is similar when trying to run in two terminals mix phoenix.server and iex -S mix phoenix.server for any phoenix app. I'm not sure about the code change above, I think a cleaner approach would be to have a dedicated mix task that starts http. (e.g.: cd apps/master_proxy && mix start.)

TBH, I don't think it's a big deal and I'd just leave it as is. I almost never use master_proxy in development (because I lose live-reloading) and instead I just start in umbrella root: iex -S mix phoenix.server. I only really needed master_proxy for heroku deployment. If you feel like fixing it though, I'd be happy to accept a PR!

enilsen16 commented 7 years ago

Yeah not a bad idea. When I tried to access acme_bank on heroku this is where I first had the issue actually.

wojtekmach commented 7 years ago

Weird, just before commenting I specifically tested if stuff was ok on heroku and it seemed fine. the app was running and I could connect with: heroku run iex -S mix without problems

W dniu pt., 11.11.2016 o 18:49 Erik Nilsen notifications@github.com napisał(a):

Yeah not a bad idea. When I tried to access acme_bank on heroku this is where I first had the issue actually.

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/wojtekmach/acme_bank/issues/10#issuecomment-260014185, or mute the thread https://github.com/notifications/unsubscribe-auth/AAEpJzdnG3xRNqUyTFxsQ2RK05cQSI8Dks5q9KqtgaJpZM4KvFQq .

enilsen16 commented 7 years ago

I am not quite sure what a mix task would look like for this particular case though. What I expected was to be able to run both side by side just like mix phoenix.server and iex -S mix. After quickly glancing at what phoenix does for the mix phoenix.server mix task, it seems to just run mix run --no-halt.

Which doesn't solve the problem of MasterProxy.Plug.HTTP starting twice. Maybe I am missing something but isn't that the problem?

enilsen16 commented 7 years ago

Also I retried acme-bank on heroku. You're right it seems to work there fine, however locally I still have issues....

enilsen16 commented 7 years ago

Closing this for now...