Skip to content

Commit

Permalink
Net::HTTP timeouts: remove ssl timeouts, TODOs
Browse files Browse the repository at this point in the history
* do not have Net::HTTP override OpenSSL specific timeouts
* add TODOs to remind us to clean things up once we specifically only
  target Ruby versions 2.6 and above
  • Loading branch information
fallwith committed Aug 1, 2023
1 parent 42a4275 commit 607f6d5
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions lib/new_relic/agent/new_relic_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ class NewRelicService
# These include Errno connection errors, and all indicate that the
# underlying TCP connection may be in a bad state.
CONNECTION_ERRORS = [Net::OpenTimeout, Net::ReadTimeout, EOFError, SystemCallError, SocketError]
# Net::WriteTimeout is Ruby 2.6+
# TODO: MAJOR VERSION - Net::WriteTimeout wasn't defined until Ruby 2.6.
# Once support for Ruby 2.5 is dropped, we should simply include
# Net::WriteTimeout in the connection errors array directly instead
# of with a conditional
CONNECTION_ERRORS << Net::WriteTimeout if defined?(Net::WriteTimeout)
CONNECTION_ERRORS.freeze

Expand Down Expand Up @@ -327,8 +330,8 @@ def start_connection(conn)
def setup_connection_timeouts(conn)
conn.open_timeout = @request_timeout
conn.read_timeout = @request_timeout
conn.ssl_timeout = @request_timeout
# #write_timeout= requires Ruby 2.6+
# TODO: MAJOR VERSION - #write_timeout= requires Ruby 2.6+, so remove
# the conditional check once support for Ruby 2.5 is dropped
conn.write_timeout = @request_timeout if conn.respond_to?(:write_timeout=)

if conn.respond_to?(:keep_alive_timeout) && NewRelic::Agent.config[:aggressive_keepalive]
Expand Down Expand Up @@ -473,7 +476,13 @@ def handle_error_response(response, endpoint)
when Net::HTTPGone
handle_gone_response(response, endpoint)
else
# Net::WriteTimeout requires Ruby 2.6+
# TODO: MAJOR VERSION - Net::WriteTimeout wasn't defined until
# Ruby 2.6, so it can't be included in the case statement
# as a constant and instead needs to be found here. Once
# support for Ruby 2.5 is dropped, we should have
# Net::WriteTimeout sit in the 'when' clause above alongside
# Net::OpenTimeout and Net::ReadTimeout and this entire if/else
# conditional can be removed.
if response.respond_to?(:name) && response.name == 'Net::WriteTimeout'
handle_server_connection_exception(response, endpoint)
else
Expand Down

0 comments on commit 607f6d5

Please sign in to comment.