mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-10-09 00:02:50 -04:00
honor operation timeout in connection
there was an inconsistency when dealing with timeouts, where the lower one would trigger a timeout error in otehr connections. we have to bookkeep per connection how much we spent before triggering.
This commit is contained in:
parent
fdb2545588
commit
83b9c645d1
@ -259,6 +259,7 @@ module HTTPX
|
|||||||
dread
|
dread
|
||||||
dwrite
|
dwrite
|
||||||
parser.consume
|
parser.consume
|
||||||
|
@timeout = @current_timeout
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -369,6 +370,9 @@ module HTTPX
|
|||||||
|
|
||||||
def transition(nextstate)
|
def transition(nextstate)
|
||||||
case nextstate
|
case nextstate
|
||||||
|
when :idle
|
||||||
|
@timeout = @current_timeout = @options.timeout.connect_timeout
|
||||||
|
|
||||||
when :open
|
when :open
|
||||||
return if @state == :closed
|
return if @state == :closed
|
||||||
|
|
||||||
@ -378,6 +382,8 @@ module HTTPX
|
|||||||
return unless @io.connected?
|
return unless @io.connected?
|
||||||
|
|
||||||
send_pending
|
send_pending
|
||||||
|
|
||||||
|
@timeout = @current_timeout = @options.timeout.operation_timeout
|
||||||
emit(:open)
|
emit(:open)
|
||||||
when :closing
|
when :closing
|
||||||
return unless @state == :open
|
return unless @state == :open
|
||||||
@ -429,21 +435,15 @@ module HTTPX
|
|||||||
else
|
else
|
||||||
@keep_alive_timer = @timers.after(@keep_alive_timeout) do
|
@keep_alive_timer = @timers.after(@keep_alive_timeout) do
|
||||||
unless @inflight.zero?
|
unless @inflight.zero?
|
||||||
log { "keep alive timeout expired, closing..." }
|
log { "(#{object_id})) keep alive timeout expired, closing..." }
|
||||||
reset
|
reset
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def on_error(ex)
|
def on_error(error)
|
||||||
handle_error(ex)
|
|
||||||
reset
|
|
||||||
end
|
|
||||||
|
|
||||||
def handle_error(error)
|
|
||||||
if error.instance_of?(TimeoutError)
|
if error.instance_of?(TimeoutError)
|
||||||
|
|
||||||
if @timeout
|
if @timeout
|
||||||
@timeout -= error.timeout
|
@timeout -= error.timeout
|
||||||
return unless @timeout <= 0
|
return unless @timeout <= 0
|
||||||
@ -457,7 +457,11 @@ module HTTPX
|
|||||||
error = error.to_connection_error
|
error = error.to_connection_error
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
handle_error(error)
|
||||||
|
reset
|
||||||
|
end
|
||||||
|
|
||||||
|
def handle_error(error)
|
||||||
parser.handle_error(error) if @parser && parser.respond_to?(:handle_error)
|
parser.handle_error(error) if @parser && parser.respond_to?(:handle_error)
|
||||||
while (request = @pending.shift)
|
while (request = @pending.shift)
|
||||||
request.emit(:response, ErrorResponse.new(request, error, @options))
|
request.emit(:response, ErrorResponse.new(request, error, @options))
|
||||||
|
@ -28,7 +28,7 @@ module HTTPX
|
|||||||
def next_tick
|
def next_tick
|
||||||
catch(:jump_tick) do
|
catch(:jump_tick) do
|
||||||
timeout = [next_timeout, @timers.wait_interval].compact.min
|
timeout = [next_timeout, @timers.wait_interval].compact.min
|
||||||
if timeout.negative?
|
if timeout && timeout.negative?
|
||||||
@timers.fire
|
@timers.fire
|
||||||
throw(:jump_tick)
|
throw(:jump_tick)
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user