mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-11-22 00:05:57 -05:00
transitioning the timeout between open and idle, depending of connection having channels connecting
This commit is contained in:
parent
befbd818b8
commit
d13864df4e
@ -292,6 +292,7 @@ module HTTPX
|
|||||||
transition(:closing)
|
transition(:closing)
|
||||||
unless parser.empty?
|
unless parser.empty?
|
||||||
transition(:closed)
|
transition(:closed)
|
||||||
|
emit(:reset)
|
||||||
transition(:idle)
|
transition(:idle)
|
||||||
transition(:open)
|
transition(:open)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -54,8 +54,12 @@ module HTTPX
|
|||||||
def build_channel(uri, **options)
|
def build_channel(uri, **options)
|
||||||
channel = Channel.by(uri, @options.merge(options))
|
channel = Channel.by(uri, @options.merge(options))
|
||||||
resolve_channel(channel)
|
resolve_channel(channel)
|
||||||
channel.once(:open) do
|
channel.on(:open) do
|
||||||
@connected_channels += 1
|
@connected_channels += 1
|
||||||
|
@timeout.transition(:open) if @channels.size == @connected_channels
|
||||||
|
end
|
||||||
|
channel.on(:reset) do
|
||||||
|
@timeout.transition(:idle)
|
||||||
end
|
end
|
||||||
channel.once(:unreachable) do
|
channel.once(:unreachable) do
|
||||||
@resolver.uncache(channel)
|
@resolver.uncache(channel)
|
||||||
@ -114,6 +118,7 @@ module HTTPX
|
|||||||
end
|
end
|
||||||
|
|
||||||
def register_channel(channel)
|
def register_channel(channel)
|
||||||
|
@timeout.transition(:idle)
|
||||||
monitor = @selector.register(channel, :w)
|
monitor = @selector.register(channel, :w)
|
||||||
monitor.value = channel
|
monitor.value = channel
|
||||||
channel.on(:close) do
|
channel.on(:close) do
|
||||||
@ -137,8 +142,7 @@ module HTTPX
|
|||||||
end
|
end
|
||||||
|
|
||||||
def next_timeout
|
def next_timeout
|
||||||
connecting = @channels.empty? || (@channels.size != @connected_channels)
|
timeout = @timeout.timeout
|
||||||
timeout = @timeout.timeout(connecting: connecting) # force log time
|
|
||||||
return (@resolver.timeout || timeout) unless @resolver.closed?
|
return (@resolver.timeout || timeout) unless @resolver.closed?
|
||||||
timeout
|
timeout
|
||||||
end
|
end
|
||||||
|
|||||||
@ -4,7 +4,6 @@ require "timeout"
|
|||||||
|
|
||||||
module HTTPX
|
module HTTPX
|
||||||
class Timeout
|
class Timeout
|
||||||
include Loggable
|
|
||||||
CONNECT_TIMEOUT = 60
|
CONNECT_TIMEOUT = 60
|
||||||
OPERATION_TIMEOUT = 60
|
OPERATION_TIMEOUT = 60
|
||||||
|
|
||||||
@ -23,15 +22,16 @@ module HTTPX
|
|||||||
@operation_timeout = operation_timeout
|
@operation_timeout = operation_timeout
|
||||||
@total_timeout = total_timeout
|
@total_timeout = total_timeout
|
||||||
if loop_timeout
|
if loop_timeout
|
||||||
log { ":loop_timeout is deprecated, use :operation_timeout instead" }
|
warn ":loop_timeout is deprecated, use :operation_timeout instead"
|
||||||
@operation_timeout = loop_timeout
|
@operation_timeout = loop_timeout
|
||||||
end
|
end
|
||||||
reset_counter
|
reset_counter
|
||||||
|
@state = :idle # this is here not to trigger the log
|
||||||
|
transition(:idle)
|
||||||
end
|
end
|
||||||
|
|
||||||
def timeout(connecting: false)
|
def timeout
|
||||||
tout = connecting ? @connect_timeout : @operation_timeout
|
@timeout || @total_timeout
|
||||||
tout || @total_timeout
|
|
||||||
ensure
|
ensure
|
||||||
log_time
|
log_time
|
||||||
end
|
end
|
||||||
@ -63,6 +63,18 @@ module HTTPX
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def transition(nextstate)
|
||||||
|
return if @state == nextstate
|
||||||
|
case nextstate
|
||||||
|
# when :idle
|
||||||
|
when :idle
|
||||||
|
@timeout = @connect_timeout
|
||||||
|
when :open
|
||||||
|
@timeout = @operation_timeout
|
||||||
|
end
|
||||||
|
@state = nextstate
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def reset_counter
|
def reset_counter
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user