You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
WEBRick::HTTPServer creates ipv6only socket for host :: #99
The IPv6 host :: is kind of analogous to the IPv4 address 0.0.0.0, however it should usually (depending on the OS) listen for traffic coming from IPv4 and IPv6 addresses, unless specified differently by the OS.
However, i have observed that across different linux distros i have tried (manjaro, arch, debian), WEBRick will open its socket in ipv6-only mode.
I assume that the reason is this line as using the Socket.tcp_server_sockets function manually leads to the same result.
However, e.g. using the TCPServer from the socket stdlib opens a socker that's not in ipv6-only mode.
I have tested this with webrick 1.7.0 on ruby 3.1.1 and on ruby 2.6.3, both yielding the same result.
I have observed the mode using ss -tlne, where the local address is shown as [::]:8080, which indicates ipv6-only mode in ss, while it should be *:8080 in non-ipv6-only mode.
It also says v6only:1 in the process description, while it should say v6only:0.
Also here's the sample code using TCPServer that correctly opens the socket:
Does anyone have a workaround for this to force webrick to serve on both IPv4 and IPv6?
I'm using jekyll serve, which uses WEBrick under the hood, and chrome randomly chooses IPv4 vs IPv6, even if I explicitly go to http://127.0.0.1:4000 or http://[::1]:4000. This means that half the assets on my page fail to load because some connect over IPv4 and some over IPv6, and only one or the other are actually hitting a listening port.
However, when booting via rackup it only binds to tcp6 and not tcp4. My conclusion would be that the problem is the interplay between rackup and webrick. I'm unsure which side (webrick or rackup) holds this problem.
$ cat Gemfile
source "https://rubygems.org"
gem "rack"
gem "rackup"
gem "webrick"
$ cat config.ru
# config.ru
require 'rack'
# Define a simple Rack application
app = Proc.new do |env|
['200', {'Content-Type' => 'text/html'}, ['Hello, world!']]
end
# Use Rack::Builder to build the application
run Rack::Builder.new {
run app
}
$ be rackup --host "::"
[2024-11-27 09:54:42] INFO WEBrick 1.9.0
[2024-11-27 09:54:42] INFO ruby 3.3.1 (2024-04-23) [arm64-darwin23]
[2024-11-27 09:54:42] INFO WEBrick::HTTPServer#start: pid=95732 port=9292
Though it's weird that it's not showing up as tcp46 like with puma[…]
I have to try finding my debugging notes on this one. This is a combination of the local network interface setup and how the TCP socket gets created. The the effect should be the same.
However, when booting via rackup it only binds to tcp6 and not tcp4.
99% sure that's a bug in rackup. There is some weird defaulting logic in the WEBrick adapter which results in localhost being passed into as Host: for WEBrick::HTTPServer.new. AFAIK setting RACK_ENV to something other than development changes this. Super weird, IMO. See https://github.com/rack/rackup/blob/main/lib/rackup/handler/webrick.rb#L19-L35.
Activity
MarkLodato commentedon Feb 8, 2023
Does anyone have a workaround for this to force webrick to serve on both IPv4 and IPv6?
I'm using
jekyll serve, which uses WEBrick under the hood, and chrome randomly chooses IPv4 vs IPv6, even if I explicitly go tohttp://127.0.0.1:4000orhttp://[::1]:4000. This means that half the assets on my page fail to load because some connect over IPv4 and some over IPv6, and only one or the other are actually hitting a listening port.tisba commentedon Aug 15, 2024
Same issue with WEBrick 1.8.1 on macOS under Ruby 3.3.4 (
arm64-darwin23).tisba commentedon Sep 21, 2024
hmm, I don't know what I did test back in August, but for me using
Host: '::'(or not specifyingHostat all) does the right thing. 🙈Will bind correctly:
This also works on macOS too. Used Ruby 3.3.5 and WEBrick 1.8.1 for testing.
I also tested with Ruby 3.1.1 and WEBrick 1.7.0, like @pohlarized did, and it also worked as expected.
schneems commentedon Nov 27, 2024
I confirm that I see webrick bind to both tcp4 and 6
Though it's weird that it's not showing up as tcp46 like with puma https://gist.github.com/schneems/ffc51f61e6ee213b29e676c89e0579d0.
schneems commentedon Nov 27, 2024
However, when booting via
rackupit only binds to tcp6 and not tcp4. My conclusion would be that the problem is the interplay between rackup and webrick. I'm unsure which side (webrick or rackup) holds this problem.tisba commentedon Nov 27, 2024
I have to try finding my debugging notes on this one. This is a combination of the local network interface setup and how the TCP socket gets created. The the effect should be the same.
99% sure that's a bug in
rackup. There is some weird defaulting logic in the WEBrick adapter which results inlocalhostbeing passed into asHost:forWEBrick::HTTPServer.new. AFAIK settingRACK_ENVto something other thandevelopmentchanges this. Super weird, IMO. See https://github.com/rack/rackup/blob/main/lib/rackup/handler/webrick.rb#L19-L35.tisba commentedon Nov 27, 2024
oh and also: I think
WEBrick::HTTPServer.newignoresHostanyway.BindAddressis what you want to use.