From f64109e1cff0b640ff6eba1bff441c229d8a2012 Mon Sep 17 00:00:00 2001 From: Misaki Shioi Date: Wed, 17 Dec 2025 13:28:38 +0900 Subject: [PATCH] Raise `Net::OpenTimeout` when `TCPSocket.open` raises `IO::TimeoutError`. With the changes in https://github.com/ruby/ruby/pull/15602, `TCPSocket.open` now raises `IO::TimeoutError` when a user-specified timeout occurs. This change updates #connect to handle this case accordingly. --- lib/net/http.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/net/http.rb b/lib/net/http.rb index 986c1a9..d551e00 100644 --- a/lib/net/http.rb +++ b/lib/net/http.rb @@ -1676,7 +1676,9 @@ def connect begin s = timeouted_connect(conn_addr, conn_port) rescue => e - e = Net::OpenTimeout.new(e) if e.is_a?(Errno::ETIMEDOUT) # for compatibility with previous versions + if (defined?(IO::TimeoutError) && e.is_a?(IO::TimeoutError)) || e.is_a?(Errno::ETIMEDOUT) # for compatibility with previous versions + e = Net::OpenTimeout.new(e) + end raise e, "Failed to open TCP connection to " + "#{conn_addr}:#{conn_port} (#{e.message})" end