lib/httpx/connection.rb in httpx-0.24.7 vs lib/httpx/connection.rb in httpx-1.0.0

- old
+ new

@@ -31,11 +31,10 @@ extend Forwardable include Loggable include Callbacks using URIExtensions - using NumericExtensions require "httpx/connection/http2" require "httpx/connection/http1" def_delegator :@io, :closed? @@ -68,11 +67,10 @@ transition(:idle) end @inflight = 0 @keep_alive_timeout = @options.timeout[:keep_alive_timeout] - @total_timeout = @options.timeout[:total_timeout] self.addresses = @options.addresses if @options.addresses end # this is a semi-private method, to be used by the resolver @@ -268,25 +266,10 @@ @pending << request end end def timeout - if @total_timeout - return @total_timeout unless @connected_at - - elapsed_time = @total_timeout - Utils.elapsed_time(@connected_at) - - if elapsed_time.negative? - ex = TotalTimeoutError.new(@total_timeout, "Timed out after #{@total_timeout} seconds") - ex.set_backtrace(caller) - on_error(ex) - return - end - - return elapsed_time - end - return @timeout if defined?(@timeout) return @options.timeout[:connect_timeout] if @state == :idle @options.timeout[:operation_timeout] @@ -602,10 +585,13 @@ return unless @write_buffer.empty? purge_after_closed when :already_open nextstate = :open + # the first check for given io readiness must still use a timeout. + # connect is the reasonable choice in such a case. + @timeout = @options.timeout[:connect_timeout] send_pending when :active return unless @state == :inactive nextstate = :open @@ -641,26 +627,19 @@ end def on_error(error) if error.instance_of?(TimeoutError) - if @total_timeout && @connected_at && - Utils.elapsed_time(@connected_at) > @total_timeout - ex = TotalTimeoutError.new(@total_timeout, "Timed out after #{@total_timeout} seconds") - ex.set_backtrace(error.backtrace) - error = ex - else - # inactive connections do not contribute to the select loop, therefore - # they should not fail due to such errors. - return if @state == :inactive + # inactive connections do not contribute to the select loop, therefore + # they should not fail due to such errors. + return if @state == :inactive - if @timeout - @timeout -= error.timeout - return unless @timeout <= 0 - end - - error = error.to_connection_error if connecting? + if @timeout + @timeout -= error.timeout + return unless @timeout <= 0 end + + error = error.to_connection_error if connecting? end handle_error(error) reset end