Skip to content

Commit

Permalink
Revert "Replace Timeout.timeout in Net:HTTP#connect"
Browse files Browse the repository at this point in the history
This reverts commit 753cae3.
  • Loading branch information
hsbt committed Oct 21, 2022
1 parent d03283d commit 98caa38
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions lib/net/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1013,13 +1013,14 @@ def connect
end

debug "opening connection to #{conn_addr}:#{conn_port}..."
begin
s = Socket.tcp conn_addr, conn_port, @local_host, @local_port, connect_timeout: @open_timeout
rescue => e
e = Net::OpenTimeout.new(e) if e.is_a?(Errno::ETIMEDOUT) #for compatibility with previous versions
raise e, "Failed to open TCP connection to " +
"#{conn_addr}:#{conn_port} (#{e.message})"
end
s = Timeout.timeout(@open_timeout, Net::OpenTimeout) {
begin
TCPSocket.open(conn_addr, conn_port, @local_host, @local_port)
rescue => e
raise e, "Failed to open TCP connection to " +
"#{conn_addr}:#{conn_port} (#{e.message})"
end
}
s.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
debug "opened"
if use_ssl?
Expand Down

1 comment on commit 98caa38

@gamecreature
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hsbt It looks like the Timeout.timout code creates an issue when starting HTTP requests from an enclosed threadgroup. airbrake/airbrake-ruby#713 (comment)
Summary: Timeout.timeout moves the waiting thread to the default threadgroup, which fails if it's called from an enclosed thread.

Please sign in to comment.