Help debugging IPv6 latency on Ruby Windows
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 148
- Forks
- 95
- Avg merge
- 10h 54m
- Merged PRs (30d)
- 4
Description
I am experiencing this issue on a Windows machine. Original issue filed with Windows Ruby installer: https://github.com/oneclick/rubyinstaller2/issues/264
It seems that the change from TcpSocket to Socket (https://github.com/ruby/net-http/pull/10) released in Ruby 3.1 is now causing timeout latency for me when accessing IPv6 sites using Net::HTTP. Socket.tcp waits 60 sec attempting connect to IPv6, times out, then immediately connects to IPv4. TCPSocket.open does not have this issue.
TCPSocket.open("google.com", 80, nil, nil) # fast
Socket.tcp("google.com", 80, nil, nil, connect_timeout: 60) # times out after 60 sec on IPv6, then falls back to IPv4
TCPSocket.open is fast on both Ruby 3.0 and 3.1, while Socket.tcp is slow on both Ruby 3.0 and 3.1. However, since Net::HTTP switched to Socket in 3.1 it has the end-result of making Net::HTTP slow overall.
The issue may be Windows-specific, since I do not see when using Linux via WSL Ubuntu on the same Windows machine. There's a lot more details in the rubyinstaller2 issue, however, I'm wondering if someone can provide some insight on how to debug this further.
Script to reproduce issue:
require 'uri'
require 'net/http'
require 'openssl'
module HTTPS_IPv4_IPv6
class << self
def run(uri_str)
uri = URI(uri_str)
puts uri_str
t_st = Process.clock_gettime(Process::CLOCK_MONOTONIC)
Net::HTTP.start(uri.host, uri.port, use_ssl: true, verify_mode: OpenSSL::SSL::VERIFY_PEER) do |http|
req = Net::HTTP::Get.new uri.request_uri
resp = http.request req
case resp
when Net::HTTPSuccess
body = resp.body
t_end = Process.clock_gettime(Process::CLOCK_MONOTONIC)
puts "body bytesize #{body.bytesize}"
puts format("response time %6.3f sec", t_end - t_st)
puts http.instance_variable_get(:@socket).io.to_io.remote_address.inspect, ''
when Net::HTTPRedirection
puts "#{resp.class}\n Redirect: #{resp['location']}"
run resp['location']
else
puts resp.class
end
end
end
end
end
puts '', RUBY_DESCRIPTION, ''
HTTPS_IPv4_IPv6.run 'https://www.google.com'
HTTPS_IPv4_IPv6.run 'https://global.jd.com'
ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x64-mingw32]
https://www.google.com
body bytesize 15110
response time 2.390 sec
#<Addrinfo: 142.251.42.196:443 TCP>
https://global.jd.com -- IPv4 only
body bytesize 20592
response time 0.633 sec
#<Addrinfo: 14.0.43.163:443 TCP>
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the supplied reproduction script on Windows using Ruby 3.0 and 3.1, comparing Net::HTTP, Socket.tcp, and TCPSocket.open for IPv6 and IPv4 destinations. Trace the connection path around the Socket.tcp change and compare it with the linked rubyinstaller2 report; done means the Windows-specific cause or next debugging boundary is documented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- networking
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100