Implement RFC 8305, the "Happy Eyeballs". #793
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This addresses #739.
Happy Eyeballs landed in Ruby for quite some time. 🎉
https://bugs.ruby-lang.org/issues/20108
However, it does not reach HTTP.rb yet.
This is because HTTP.rb uses TCPSocket.open by default.
Source traces
open
was implemented in the IO class as an alias tonew
.https://github.com/ruby/ruby/blob/37a16c7812f5b7e6faa762b927e9f04065cc495a/io.c#L8124
TCPSocket
, it is bound directly to the c source code.https://github.com/ruby/ruby/blob/6deeec5d459ecff5ec4628523b14ac7379fd942e/ext/socket/tcpsocket.c#L54
ruby/ruby@9ec342e
A baby step
In order to take advantage of the new feature. I alias
default_socket_class
toSocket.tcp
so the connection logic will be handled by the Ruby layer ofSocket
.Rough edges
For your information
Socket.tcp
has a lot of features beyond Happy Eyeballs.For example, it supports
connect_timeout
natively.What to do with
http/lib/http/timeout/global.rb
Line 24 in db6863a
This is just one aspect of it.
Nevertheless, this baby step would introduce minimal breaking changes. (or any changes at all)
Providing more robust connections.