fixing overwriting connection #transition, which wasn't taking tcp connect on proxy errors

This commit is contained in:
HoneyryderChuck 2021-12-20 17:52:00 +00:00
parent f3d50e6a06
commit 1343c74e31
7 changed files with 21 additions and 15 deletions

View File

@ -489,6 +489,18 @@ module HTTPX
end end
def transition(nextstate) 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 case nextstate
when :idle when :idle
@timeout = @current_timeout = @options.timeout[:connect_timeout] @timeout = @current_timeout = @options.timeout[:connect_timeout]
@ -525,14 +537,6 @@ module HTTPX
emit(:activate) emit(:activate)
end end
@state = nextstate @state = nextstate
rescue Errno::ECONNREFUSED,
Errno::EADDRNOTAVAIL,
Errno::EHOSTUNREACH,
TLSError => e
# connect errors, exit gracefully
handle_error(e)
@state = :closed
emit(:close)
end end
def purge_after_closed def purge_after_closed

View File

@ -57,7 +57,9 @@ module HTTPX
@io = build_socket @io = build_socket
end end
try_connect try_connect
rescue Errno::EHOSTUNREACH => e rescue Errno::ECONNREFUSED,
Errno::EADDRNOTAVAIL,
Errno::EHOSTUNREACH => e
raise e if @ip_index <= 0 raise e if @ip_index <= 0
@ip_index -= 1 @ip_index -= 1

View File

@ -81,7 +81,7 @@ module HTTPX
super super
end end
def transition(nextstate) def handle_transition(nextstate)
state = @state state = @state
super super
meter_elapsed_time("Connection##{object_id}[#{@origin}]: #{state} -> #{nextstate}") if nextstate == @state meter_elapsed_time("Connection##{object_id}[#{@origin}]: #{state} -> #{nextstate}") if nextstate == @state

View File

@ -234,7 +234,7 @@ module HTTPX
end end
end end
def transition(nextstate) def handle_transition(nextstate)
return super unless @options.proxy return super unless @options.proxy
case nextstate case nextstate

View File

@ -13,7 +13,7 @@ module HTTPX
private private
def transition(nextstate) def handle_transition(nextstate)
return super unless @options.proxy && @options.proxy.uri.scheme == "http" return super unless @options.proxy && @options.proxy.uri.scheme == "http"
case nextstate case nextstate
@ -54,7 +54,7 @@ module HTTPX
@inflight += 1 @inflight += 1
parser.send(connect_request) parser.send(connect_request)
else else
transition(:connected) handle_transition(:connected)
end end
end end

View File

@ -27,7 +27,7 @@ module HTTPX
private private
def transition(nextstate) def handle_transition(nextstate)
return super unless @options.proxy && PROTOCOLS.include?(@options.proxy.uri.scheme) return super unless @options.proxy && PROTOCOLS.include?(@options.proxy.uri.scheme)
case nextstate case nextstate

View File

@ -46,7 +46,7 @@ module HTTPX
private private
def transition(nextstate) def handle_transition(nextstate)
return super unless @options.proxy && @options.proxy.uri.scheme == "socks5" return super unless @options.proxy && @options.proxy.uri.scheme == "socks5"
case nextstate case nextstate