summaryrefslogtreecommitdiff
path: root/ext/socket/lib
diff options
context:
space:
mode:
authorMisaki Shioi <31817032+shioimm@users.noreply.github.com>2025-12-17 16:16:32 +0900
committerGitHub <noreply@github.com>2025-12-17 16:16:32 +0900
commit54d3945ee53fa29186c6aa44f673a3a5ec3b38d9 (patch)
tree136e3348b58d35df7d71e466ce48f4e13b5c6f51 /ext/socket/lib
parent1506c489eef67f268a54484662011a60897bdd48 (diff)
Add host information to timeout error messages in `TCPSocket.new` and `Socket.tcp` (#15582)
This change adds host information to the error messages shown when a timeout occurs while passing timeout options to `TCPSocket.new` or `Socket.tcp`, for improved usability. (When the `fast_fallback option` is enabled, there may be multiple possible destinations, so the host name is shown instead of an IP address.) As part of this change, the error messages in `Addrinfo.getaddrinfo` and `Addrinfo#connect_internal`, both of which are used by `Socket.tcp`, have also been improved in the same way.
Diffstat (limited to 'ext/socket/lib')
-rw-r--r--ext/socket/lib/socket.rb8
1 files changed, 5 insertions, 3 deletions
diff --git a/ext/socket/lib/socket.rb b/ext/socket/lib/socket.rb
index 6d04ca2483..e74eaec43a 100644
--- a/ext/socket/lib/socket.rb
+++ b/ext/socket/lib/socket.rb
@@ -62,7 +62,7 @@ class Addrinfo
break
when :wait_writable
sock.wait_writable(timeout) or
- raise Errno::ETIMEDOUT, 'user specified timeout'
+ raise Errno::ETIMEDOUT, "user specified timeout for #{self.ip_address}:#{self.ip_port}"
end while true
else
sock.connect(self)
@@ -905,7 +905,9 @@ class Socket < BasicSocket
end
end
- raise(IO::TimeoutError, 'user specified timeout') if expired?(now, user_specified_open_timeout_at)
+ if expired?(now, user_specified_open_timeout_at)
+ raise(IO::TimeoutError, "user specified timeout for #{host}:#{port}")
+ end
if resolution_store.empty_addrinfos?
if connecting_sockets.empty? && resolution_store.resolved_all_families?
@@ -918,7 +920,7 @@ class Socket < BasicSocket
if (expired?(now, user_specified_resolv_timeout_at) || resolution_store.resolved_all_families?) &&
(expired?(now, user_specified_connect_timeout_at) || connecting_sockets.empty?)
- raise IO::TimeoutError, 'user specified timeout'
+ raise(IO::TimeoutError, "user specified timeout for #{host}:#{port}")
end
end
end