summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMisaki Shioi <31817032+shioimm@users.noreply.github.com>2025-02-03 20:26:47 +0900
committerGitHub <noreply@github.com>2025-02-03 20:26:47 +0900
commit1683dadb19876f0a64589bdbbcf6fff8143f78ff (patch)
tree5553a078e2ee030aef9111c6ae610c240c400f58 /test
parentf84d75eeccc38d298692c564d30f4e018d03f35d (diff)
Do not save ResolutionError if resolution succeeds for any address family (#12678)
* Do not save ResolutionError if resolution succeeds for any address family Socket with Happy Eyeballs Version 2 performs connection attempts and name resolution in parallel. In the existing implementation, if a connection attempt failed for one address family while name resolution was still in progress for the other, and that name resolution later failed, the method would terminate with a name resolution error. This behavior was intended to ensure that the final error reflected the most recent failure, potentially overriding an earlier error. However, [Bug #21088](https://bugs.ruby-lang.org/issues/21088) made me realize that terminating with a name resolution error is unnatural when name resolution succeeded for at least one address family. This PR modifies the behavior so that if name resolution succeeds for one address family, any name resolution error from the other is not saved. This PR includes the following changes: * Do not display select(2) as the system call that caused the raised error, as it is for internal processing * Fix bug: Get errno with Socket::SO_ERROR in Windows environment with a workaround for tests not passing
Notes
Notes: Merged-By: shioimm <shioi.mm@gmail.com>
Diffstat (limited to 'test')
-rw-r--r--test/socket/test_socket.rb22
-rw-r--r--test/socket/test_tcp.rb2
2 files changed, 23 insertions, 1 deletions
diff --git a/test/socket/test_socket.rb b/test/socket/test_socket.rb
index 4d75caab50..27e60b3335 100644
--- a/test/socket/test_socket.rb
+++ b/test/socket/test_socket.rb
@@ -995,6 +995,28 @@ class TestSocket < Test::Unit::TestCase
RUBY
end
+ def test_tcp_socket_hostname_resolution_failed_after_connection_failure
+ opts = %w[-rsocket -W1]
+ assert_separately opts, <<~RUBY
+ server = TCPServer.new("127.0.0.1", 0)
+ port = server.connect_address.ip_port
+
+ Addrinfo.define_singleton_method(:getaddrinfo) do |_, _, family, *_|
+ case family
+ when Socket::AF_INET6 then sleep(0.1); raise Socket::ResolutionError
+ when Socket::AF_INET then [Addrinfo.tcp("127.0.0.1", port)]
+ end
+ end
+
+ server.close
+
+ # SystemCallError is a workaround for Windows environment
+ assert_raise(Errno::ECONNREFUSED, SystemCallError) do
+ Socket.tcp("localhost", port)
+ end
+ RUBY
+ end
+
def test_tcp_socket_v6_address_passed
opts = %w[-rsocket -W1]
assert_separately opts, <<~RUBY
diff --git a/test/socket/test_tcp.rb b/test/socket/test_tcp.rb
index 4984a7e7bc..e6a41f5660 100644
--- a/test/socket/test_tcp.rb
+++ b/test/socket/test_tcp.rb
@@ -316,7 +316,7 @@ class TestSocket_TCPSocket < Test::Unit::TestCase
port = server.connect_address.ip_port
server.close
- assert_raise(Socket::ResolutionError) do
+ assert_raise(Errno::ECONNREFUSED) do
TCPSocket.new(
"localhost",
port,