lib/httpx/connection.rb in httpx-0.18.6 vs lib/httpx/connection.rb in httpx-0.18.7
- old
+ new
@@ -42,11 +42,11 @@
def_delegator :@io, :closed?
def_delegator :@write_buffer, :empty?
- attr_reader :origin, :state, :pending, :options
+ attr_reader :origin, :origins, :state, :pending, :options
attr_writer :timers
def initialize(type, uri, options)
@type = type
@@ -487,10 +487,22 @@
end
end
end
def transition(nextstate)
+ handle_transition(nextstate)
+ rescue Errno::ECONNREFUSED,
+ Errno::EADDRNOTAVAIL,
+ Errno::EHOSTUNREACH,
+ TLSError => e
+ # connect errors, exit gracefully
+ handle_error(e)
+ @state = :closed
+ emit(:close)
+ end
+
+ def handle_transition(nextstate)
case nextstate
when :idle
@timeout = @current_timeout = @options.timeout[:connect_timeout]
when :open
@@ -523,18 +535,10 @@
nextstate = :open
emit(:activate)
end
@state = nextstate
- rescue Errno::ECONNREFUSED,
- Errno::EADDRNOTAVAIL,
- Errno::EHOSTUNREACH,
- TLSError => e
- # connect errors, exit gracefully
- handle_error(e)
- @state = :closed
- emit(:close)
end
def purge_after_closed
@io.close if @io
@read_buffer.clear
@@ -548,9 +552,13 @@
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 fail due to such errors.
+ return if @state == :inactive
+
if @timeout
@timeout -= error.timeout
return unless @timeout <= 0
end