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
[DOC] Improve Socket::tcp with Happy Eyeballs Version 2
With the introduction of Happy Eyeballs Version 2 to `Socket::tcp`, the following areas have been mainly enhanced:
- How the value specified for `connect_timeout` works
- How Socket.tcp operates with Happy Eyeballs Version 2
A description for the new option `fast_fallback` has been added in ruby#11813.
Copy file name to clipboardExpand all lines: ext/socket/lib/socket.rb
+28-3Lines changed: 28 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -629,15 +629,22 @@ class << self
629
629
#
630
630
# creates a new socket object connected to host:port using TCP/IP.
631
631
#
632
+
# Starting from Ruby 3.4, this method operates according to the
633
+
# Happy Eyeballs Version 2 ({RFC 8305}[https://datatracker.ietf.org/doc/html/rfc8305])
634
+
# algorithm by default.
635
+
#
636
+
# To make it behave the same as in Ruby 3.3 and earlier,
637
+
# explicitly specify the option +fast_fallback:false+.
638
+
#
632
639
# If local_host:local_port is given,
633
640
# the socket is bound to it.
634
641
#
635
642
# The optional last argument _opts_ is options represented by a hash.
636
643
# _opts_ may have following options:
637
644
#
638
-
# [:resolv_timeout] specify the timeout of hostname resolution in seconds.
639
-
# [:connect_timeout] specify the timeout of conncetion in seconds.
640
-
# [:fast_fallback] enable Happy Eyeballs Version 2 ({RFC 8305}[https://datatracker.ietf.org/doc/html/rfc8305]) algorithm (Enabled by default).
645
+
# [:resolv_timeout] Specifies the timeout in seconds from when the hostname resolution starts.
646
+
# [:connect_timeout] This method sequentially attempts connecting to all candidate destination addresses.<br>The +connect_timeout+ specifies the timeout in seconds from the start of the connection attempt to the last candidate.<br>By default, all connection attempts continue until the timeout occurs.<br>When +fast_fallback:false+ is explicitly specified,<br>a timeout is set for each connection attempt and any connection attempt that exceeds its timeout will be canceled.
647
+
# [:fast_fallback] Enables the Happy Eyeballs Version 2 algorithm (enabled by default).
641
648
#
642
649
# If a block is given, the block is called with the socket.
643
650
# The value of the block is returned.
@@ -650,6 +657,24 @@ class << self
650
657
# sock.close_write
651
658
# puts sock.read
652
659
# }
660
+
#
661
+
# === Happy Eyeballs Version 2
662
+
# Happy Eyeballs Version 2 ({RFC 8305}[https://datatracker.ietf.org/doc/html/rfc8305])
663
+
# is an algorithm designed to improve client socket connectivity.<br>
664
+
# It aims for more reliable and efficient connections by performing hostname resolution
665
+
# and connection attempts in parallel, instead of serially.
666
+
#
667
+
# Starting from Ruby 3.4, this method operates as follows with this algorithm:
668
+
#
669
+
# 1. Start resolving both IPv6 and IPv4 addresses concurrently.
670
+
# 2. Start connecting to the one of the addresses that are obtained first.<br>If IPv4 addresses are obtained first,
671
+
# the method waits 50 ms for IPv6 name resolution to prioritize IPv6 connections.
672
+
# 3. After starting a connection attempt, wait 250 ms for the connection to be established.<br>
673
+
# If no connection is established within this time, a new connection is started every 250 ms<br>
674
+
# until a connection is established or there are no more candidate addresses.<br>
0 commit comments