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
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]
@ -525,14 +537,6 @@ module HTTPX
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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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