Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 753cae3

Browse files
committed
Replace Timeout.timeout in Net:HTTP#connect
Use Socket.tcp's connect_timeout option instead
1 parent d9ba437 commit 753cae3

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

lib/net/http.rb

+7-8
Original file line numberDiff line numberDiff line change
@@ -982,14 +982,13 @@ def connect
982982
end
983983

984984
D "opening connection to #{conn_addr}:#{conn_port}..."
985-
s = Timeout.timeout(@open_timeout, Net::OpenTimeout) {
986-
begin
987-
TCPSocket.open(conn_addr, conn_port, @local_host, @local_port)
988-
rescue => e
989-
raise e, "Failed to open TCP connection to " +
990-
"#{conn_addr}:#{conn_port} (#{e.message})"
991-
end
992-
}
985+
begin
986+
s = Socket.tcp conn_addr, conn_port, @local_host, @local_port, connect_timeout: @open_timeout
987+
rescue => e
988+
e = Net::OpenTimeout.new(e) if e.is_a?(Errno::ETIMEDOUT) #for compatibility with previous versions
989+
raise e, "Failed to open TCP connection to " +
990+
"#{conn_addr}:#{conn_port} (#{e.message})"
991+
end
993992
s.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
994993
D "opened"
995994
if use_ssl?

0 commit comments

Comments
 (0)