Skip to content
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

3.8.0: rails s -b 0.0.0.0 will set port to default puma port #1255

Closed
noelblaschke opened this issue Mar 27, 2017 · 12 comments
Closed

3.8.0: rails s -b 0.0.0.0 will set port to default puma port #1255

noelblaschke opened this issue Mar 27, 2017 · 12 comments
Assignees

Comments

@noelblaschke
Copy link

noelblaschke commented Mar 27, 2017

Steps to reproduce

  1. install rails with puma version 3.8.0/1/2
  2. run rails s -b 0.0.0.0

Expected behavior

Listening on tcp://0.0.0.0:3000

Actual behavior

Listening on tcp://0.0.0.0:9292

System configuration

In docker env:
Ruby version: 2.4.1
Rails version: 5.1.0rc1, not tested with 4.x

Quick solution

Run rails s -b 0.0.0.0 -p 3000

@toshimaru
Copy link

toshimaru commented Apr 3, 2017

Same here.

This was introduced by #1234, which adds 3 different sources of configuration.

I tried to fix this, but I'm not sure my code is correct:

host = options[:Host] || default_options[:Host] || ::Puma::Configuration::DefaultTCPHost
port = options[:Port] || default_options[:Port] || ::Puma::Configuration::DefaultTCPPort
self.set_host_port_to_config(host, port, user_config)

(This code doesn't care default_config, so I'm not sure my code is correct)

@nateberkopec
Copy link
Member

Paging @schneems

@schneems
Copy link
Contributor

schneems commented Apr 7, 2017

Well 💩. Thanks for the issue. I'll be able to take a look but it probably won't be for a few days I'm currently a bit sick.

@schneems schneems self-assigned this Apr 14, 2017
@schneems
Copy link
Contributor

So. I'm seeing a different behavior:

$ rails s -b 0.0.0.0
/Users/schneems/.gem/ruby/2.4.1/gems/activesupport-5.0.1.rc2/lib/active_support/xml_mini.rb:51: warning: constant ::Fixnum is deprecated
/Users/schneems/.gem/ruby/2.4.1/gems/activesupport-5.0.1.rc2/lib/active_support/xml_mini.rb:52: warning: constant ::Bignum is deprecated
[tunemygc] not enabled
=> Booting Puma
=> Rails 5.0.1.rc2 application starting in development on http://0.0.0.0:3000

Can you give me an example app that reproduces the problem?

@tricknotes
Copy link
Contributor

tricknotes commented Apr 16, 2017

@schneems

You can see the full logs.

Can you give me an example app that reproduces the problem?

here.

$ rails s -b 0.0.0.0
=> Booting Puma
=> Rails 5.1.0.rc1 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.8.2 (ruby 2.3.3-p222), codename: Sassy Salamander
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://0.0.0.0:9292
Use Ctrl-C to stop

I think this puma server listens tcp://0.0.0.0:9292, not http://0.0.0.0:3000.

Incidentally, this is a just generated rails application by the following command:

$ rails -v
Rails 5.1.0.rc1
$ rails new demo

@toshimaru
Copy link

toshimaru commented Apr 21, 2017

Seems this has been fixed in rails-side at Rails 5.1.0.rc2. seems not fixed yet

see, rails/rails#28513

$ rails s -b 0.0.0.0
=> Booting Puma
=> Rails 5.1.0.rc2 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.8.2 (ruby 2.3.3-p222), codename: Sassy Salamander
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://0.0.0.0:3000
Use Ctrl-C to stop

@matiaskorhonen
Copy link

This still seems to happen with Rails 5.1.0.rc2 (not sure who's fault it is, Rails or Puma…):

» ./bin/rails s -b 0.0.0.0
=> Booting Puma
=> Rails 5.1.0.rc2 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.8.2 (ruby 2.4.1-p111), codename: Sassy Salamander
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://0.0.0.0:9292
Use Ctrl-C to stop

@toshimaru
Copy link

toshimaru commented Apr 24, 2017

oh, sorry, I might be using my forked puma gem... It seems not fixed yet...

@matiaskorhonen
Copy link

Just to confirm, I just tested this on a brand new Rails app generated with Rails 5.1.0.rc2 on Ruby 2.4.1 (on macOS Sierra). The same issue persists.

@schneems
Copy link
Contributor

Able to repro with rails master

$ rails s -b 0.0.0.0
=> Booting Puma
=> Rails 5.2.0.alpha application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.8.2 (ruby 2.4.1-p111), codename: Sassy Salamander
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://0.0.0.0:9292

@schneems
Copy link
Contributor

The issue is how we're doing defaults

          self.set_host_port_to_config(options[:Host], options[:Port], config: user_config)
          self.set_host_port_to_config(default_options[:Host], default_options[:Port], config: default_config)

What is happening is options[:Host] is 0.0.0.0. However options[:Port] is blank, this is because 3000 is a default option and not supplied explicitly. It is passed along via default_options[:Port] which is 3000.

Here's that method

      def self.set_host_port_to_config(host, port, config:, defaults:)
        if host && (host[0,1] == '.' || host[0,1] == '/')
          config.bind "unix://#{host}"
        elsif host && host =~ /^ssl:\/\//
          uri = URI.parse(host)
          uri.port ||= port || ::Puma::Configuration::DefaultTCPPort
          config.bind uri.to_s
        else

          if host
            port ||= ::Puma::Configuration::DefaultTCPPort
          end

          if port
            host ||= ::Puma::Configuration::DefaultTCPHost
            config.port port, host
          end
        end
      end

schneems added a commit that referenced this issue Apr 27, 2017
To build a "binds" we need a host IP (via Host) and a port. We were running into a problem where a Host was being explicitly set via user but the Port was being defaulted to by Rails. When this happened the Host was used, but Puma would accidentally use it's own default port 9292 instead of Rail's port of 3000.

The fix was to use the "default" port passed in from a framework (if available) when no explicitly set Port is provided.
@asadakbar
Copy link

asadakbar commented Apr 27, 2017

We are hitting the same issue. Any thoughts as to a fix? For now we are explicitly setting the port in our docker spin up script.

Edit: Ah, I see the commit. Thanks for all your hard work!

ebizboy pushed a commit to Poponedev/puma that referenced this issue May 15, 2017
To build a "binds" we need a host IP (via Host) and a port. We were running into a problem where a Host was being explicitly set via user but the Port was being defaulted to by Rails. When this happened the Host was used, but Puma would accidentally use it's own default port 9292 instead of Rail's port of 3000.

The fix was to use the "default" port passed in from a framework (if available) when no explicitly set Port is provided.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants