introducing the ConnectTimeoutError, releasing it on timeout errors on channels when the channel is still connecting

This commit is contained in:
HoneyryderChuck 2018-10-02 09:56:03 +01:00
parent 03376524fe
commit d9c7edceea
4 changed files with 24 additions and 3 deletions

View File

@ -141,6 +141,10 @@ module HTTPX
end
end
def connecting?
@state == :idle
end
def interests
return :w if @state == :idle
readable = !@read_buffer.full?

View File

@ -32,8 +32,13 @@ module HTTPX
monitor.interests = channel.interests
end
end
rescue TimeoutError,
Errno::ECONNRESET,
rescue TimeoutError => timeout_error
@channels.each do |ch|
error = timeout_error
error = error.to_connection_error if ch.connecting?
ch.emit(:error, error)
end
rescue Errno::ECONNRESET,
Errno::ECONNABORTED,
Errno::EPIPE => ex
@channels.each do |ch|

View File

@ -5,7 +5,15 @@ module HTTPX
UnsupportedSchemeError = Class.new(Error)
TimeoutError = Class.new(Error)
TimeoutError = Class.new(Error) do
def to_connection_error
ex = ConnectTimeoutError.new(message)
ex.set_backtrace(backtrace)
ex
end
end
ConnectTimeoutError = Class.new(TimeoutError)
ResolveError = Class.new(Error)

View File

@ -119,6 +119,10 @@ module HTTPX
@pending << [request, args]
end
def connecting?
super || @state == :connecting || @state == :connected
end
def to_io
case @state
when :idle