mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-12-15 00:01:02 -05:00
downgrade to udp when retrying dns queries
This commit is contained in:
parent
3a3188efff
commit
2d6fde2e5d
@ -144,6 +144,8 @@ module HTTPX
|
||||
|
||||
if !@timeouts[host].empty?
|
||||
log { "resolver: timeout after #{timeout}s, retry(#{@timeouts[host].first}) #{host}..." }
|
||||
# must downgrade to tcp AND retry on same host as last
|
||||
downgrade_socket
|
||||
resolve(connection)
|
||||
elsif @ns_index + 1 < @nameserver.size
|
||||
# try on the next nameserver
|
||||
@ -189,10 +191,9 @@ module HTTPX
|
||||
next unless @large_packet.full?
|
||||
|
||||
parse(@large_packet.to_s)
|
||||
@socket_type = @resolver_options.fetch(:socket_type, :udp)
|
||||
@large_packet = nil
|
||||
transition(:idle)
|
||||
transition(:open)
|
||||
# downgrade to udp again
|
||||
downgrade_socket
|
||||
return
|
||||
else
|
||||
size = @read_buffer[0, 2].unpack1("n")
|
||||
@ -313,6 +314,12 @@ module HTTPX
|
||||
if catch(:coalesced) { early_resolve(connection, hostname: hostname_alias) }
|
||||
@connections.delete(connection)
|
||||
else
|
||||
if @socket_type == :tcp
|
||||
# must downgrade to udp if tcp
|
||||
@socket_type = @resolver_options.fetch(:socket_type, :udp)
|
||||
transition(:idle)
|
||||
transition(:open)
|
||||
end
|
||||
log { "resolver: ALIAS #{hostname_alias} for #{name}" }
|
||||
resolve(connection, hostname_alias)
|
||||
return
|
||||
@ -390,6 +397,14 @@ module HTTPX
|
||||
end
|
||||
end
|
||||
|
||||
def downgrade_socket
|
||||
return unless @socket_type == :tcp
|
||||
|
||||
@socket_type = @resolver_options.fetch(:socket_type, :udp)
|
||||
transition(:idle)
|
||||
transition(:open)
|
||||
end
|
||||
|
||||
def transition(nextstate)
|
||||
case nextstate
|
||||
when :idle
|
||||
|
||||
@ -59,6 +59,8 @@ module HTTPX
|
||||
|
||||
def build_socket: () -> (UDP | TCP)
|
||||
|
||||
def downgrade_socket: () -> void
|
||||
|
||||
def transition: (Symbol nextstate) -> void
|
||||
|
||||
def handle_error: (NativeResolveError | StandardError) -> void
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user