Why is Puma attached only to tcp6? (via `rails s`)

A new Rails 4.2.0 project has been created. Ran rails s , behaved as expected using WEBrick:

 vagrant@web1 :~$ netstat -nlpt Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 127.0.0.1:3000 0.0.0.0:* LISTEN 27158/ruby2.1 tcp6 0 0 ::1:3000 :::* LISTEN 27158/ruby2.1 

Added puma to the Gemfile, launched the package, then rails s again; came up with Puma, but only linked the tcp6 interface, not tcp:

 vagrant@web1 :~$ netstat -nlpt Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp6 0 0 ::1:3000 :::* LISTEN 27116/ruby2.1 

Which key? I did not search for searches.

UPDATE:

puma -b tcp://0.0.0.0:3000 . However, adding the bind directive to config / puma.rb and starting rails s fails:

 bind 'tcp://0.0.0.0:3000' 

The threads / workers directives in my configuration file work, however, I know that the configuration file is being downloaded and used. (He even added a puts statement to be sure.)

The configuration file is even matched if I just run puma , binding to the correct interface. I just need to resort to running puma instead of rails s , although this is annoying and should be added to my developer docs.

UPDATE2:

I was wrong. Running rails s does not automatically take config / puma.rb. Continuing the investigation ...

+8
ruby-on-rails ipv6 puma
source share
2 answers

Running rails like:

 rails s -b 0.0.0.0 

works for me. The problem is that "localhost" (the default binding address) is bound to IPv4 and IPv6, and v6 is selected if both are available. 0.0.0.0 forcibly use an IPv4 address (also works with 127.0.0.1 ).

+1
source share

The problem you see is that Puma binds to localhost by default. This is treated as the usual hostname by the underlying Rails TcpServer and is only resolved to one IP address (IPv6 version in your case), but not to IPv4 and IPv6 versions.

This was fixed in Puma Release No. 782 and resolved on July 18, 2016 using this patch . In current versions, an exception is made specifically for localhost , which now binds to both IPv4 and IPv6 permissions.

For all other domains, Puma will still bind to the first IP address returned by the system name resolution. In these cases, you can at least choose whether you want Puma to communicate with IPv4 or IPv6 resolution by adding the appropriate entry to /etc/hosts .

0
source share

All Articles