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
Address already in use 127.0.0.1 port 9293 error while trying to start two instances of Puma on localhost #3142
Comments
Hm, could we make it easier to discover this for people? Maybe in |
Because they are different options, sometimes, users have to read the docs :-) See the docs on The option you are looking for is $ echo 'app { [200, {}, ["OK"]] }\nactivate_control_app "tcp://0.0.0.0:9393"' | puma --config /dev/stdin
Puma starting in single mode...
* Puma version: 6.3.0 (ruby 3.2.2-p53) ("Mugi No Toki Itaru")
* Min threads: 0
* Max threads: 5
* Environment: development
* PID: 28402
* Listening on http://0.0.0.0:9292
* Starting control server on http://0.0.0.0:9393
Use Ctrl-C to stop
^C- Gracefully stopping, waiting for requests to finish
=== puma shutdown: 2023-08-01 19:09:03 +0200 ===
- Goodbye! |
I do agree Puma could be improved, showing an better error message, here is repro using only Puma: $ echo 'app { [200, {}, ["OK"]] }\nactivate_control_app "tcp://0.0.0.0:9292"' | puma --config /dev/stdin
Puma starting in single mode...
* Puma version: 6.3.0 (ruby 3.2.2-p53) ("Mugi No Toki Itaru")
* Min threads: 0
* Max threads: 5
* Environment: development
* PID: 28326
* Listening on http://0.0.0.0:9292
/Users/dentarg/.arm64_rubies/3.2.2/lib/ruby/gems/3.2.0/gems/puma-6.3.0/lib/puma/binder.rb:334:in `initialize': Address already in use - bind(2) for "0.0.0.0" port 9292 (Errno::EADDRINUSE)
from /Users/dentarg/.arm64_rubies/3.2.2/lib/ruby/gems/3.2.0/gems/puma-6.3.0/lib/puma/binder.rb:334:in `new'
from /Users/dentarg/.arm64_rubies/3.2.2/lib/ruby/gems/3.2.0/gems/puma-6.3.0/lib/puma/binder.rb:334:in `add_tcp_listener'
from /Users/dentarg/.arm64_rubies/3.2.2/lib/ruby/gems/3.2.0/gems/puma-6.3.0/lib/puma/binder.rb:163:in `block in parse'
from /Users/dentarg/.arm64_rubies/3.2.2/lib/ruby/gems/3.2.0/gems/puma-6.3.0/lib/puma/binder.rb:146:in `each'
from /Users/dentarg/.arm64_rubies/3.2.2/lib/ruby/gems/3.2.0/gems/puma-6.3.0/lib/puma/binder.rb:146:in `parse'
from /Users/dentarg/.arm64_rubies/3.2.2/lib/ruby/gems/3.2.0/gems/puma-6.3.0/lib/puma/runner.rb:78:in `start_control'
from /Users/dentarg/.arm64_rubies/3.2.2/lib/ruby/gems/3.2.0/gems/puma-6.3.0/lib/puma/single.rb:50:in `run'
from /Users/dentarg/.arm64_rubies/3.2.2/lib/ruby/gems/3.2.0/gems/puma-6.3.0/lib/puma/launcher.rb:194:in `run'
from /Users/dentarg/.arm64_rubies/3.2.2/lib/ruby/gems/3.2.0/gems/puma-6.3.0/lib/puma/cli.rb:75:in `run'
from /Users/dentarg/.arm64_rubies/3.2.2/lib/ruby/gems/3.2.0/gems/puma-6.3.0/bin/puma:10:in `<top (required)>'
from /Users/dentarg/.arm64_rubies/3.2.2/bin/puma:25:in `load'
from /Users/dentarg/.arm64_rubies/3.2.2/bin/puma:25:in `<main>' |
#3204 |
Puma version: 6.2.2 (ruby 3.1.2-p20)
I tried to start two instances of Puma server (one API and another WebApp) (through hanami gem based application) on my development machine but was unable to start the server for WebApp successfully. API server started normally but WebApp server showed error
Address already in use - bind(2) for "127.0.0.1" port 9293
.Please find below the server startup logs.
API App Logs
WebApp Logs
Following is the Puma config file
app/config/puma.rb
content. In both the applications the configuration is identical.So for my WebApp I tried making following changes to
my_web_app/config/puma.rb
based on the suggestions in #2113but no luck.
Exploring more I found few more resources at following locations
#782
#1022
#1318
but couldn't get exactly what I should do in my case.
Just in case it helps following are the contents of my
/etc/hosts
So I tried seeking help from hanami community and Stackoverflow and I received a response to my Stackoverflow post wherein it was suggested to do following:
And trying that out it solved my problem. But it raised another question in mind that why the
--control-url
option worked but not thebind
configuration option I defined in my puma config file (please refer the code snippets shared above).As can be seen in the logs shared hanami automatically starts Puma available in my applications Gemfile. So the options defined in puma config should be used by Puma, right? Also the documentation for
hanami server
command implementation (shown below)https://github.com/hanami/cli/blob/v2.0.3/lib/hanami/cli/commands/app/server.rb#L12-L27
says
So that way also the puma config options should get passed to Puma when
Rack::Server
internally invokes Puma (as part of invocations referenced below), right?https://github.com/puma/puma/blob/v6.2.2/lib/rack/handler/puma.rb#L136
https://github.com/hanami/cli/blob/v2.0.3/lib/hanami/cli/commands/app/server.rb#L49
https://github.com/hanami/cli/blob/v2.0.3/lib/hanami/cli/server.rb#L29
https://github.com/rack/rack/blob/v2.2.7/lib/rack/server.rb#L52
https://github.com/rack/rack/blob/v2.2.7/lib/rack/server.rb#L167
https://github.com/rack/rack/blob/v2.2.7/lib/rack/handler.rb#L60
https://github.com/rack/rack/blob/v2.2.7/lib/rack/handler.rb#L40
https://github.com/rack/rack/blob/v2.2.7/lib/rack/handler.rb#L13
Note: Above links refer the version of code my applications uses hanami (2.0.3), hanami-cli (2.0.3), rack (2.2.7).
And
bind
is documented as a supported config option at following link https://github.com/puma/puma/tree/v6.2.2#binding-tcp--sockets and also in the DSL at https://github.com/puma/puma/blob/master/lib/puma/dsl.rb#L245-L277 (DSL reference found under https://github.com/puma/puma/tree/v6.2.2#configuration-file)**So the question is: are there differences between
bind
andcontrol-url
options because of which when definedbind
option in my puma config file it didn't worked but using thecontrol-url
option directly from command line worked? If yes, then in which contexts each of those options should be used?A subjective thought: I thought it would be easy to just use a different port for starting both the instances but a lot of hours passed to find out the cause for the issue I shared but still I couldn't find a solution and had to seek help from community. I don't think starting multiple instances of server on same machine is a rare scenario and that too esp for development purpose and it's really unfortunate if it can't be achieved in smooth manner.
Thanks.
The text was updated successfully, but these errors were encountered: