fix: https resolver should close when no more outstanding connections are around

This commit is contained in:
HoneyryderChuck 2021-12-16 11:50:57 +00:00
parent 06b162b6ea
commit 82b0a4bf28
7 changed files with 25 additions and 7 deletions

View File

@ -25,6 +25,8 @@ require "mutex_m"
# Top-Level Namespace
#
module HTTPX
EMPTY = [].freeze
# All plugins should be stored under this module/namespace. Can register and load
# plugins.
#

View File

@ -2,8 +2,6 @@
module HTTPX
class Headers
EMPTY = [].freeze
class << self
def new(headers = nil)
return headers if headers.is_a?(self)

View File

@ -55,9 +55,19 @@ module HTTPX
connections = connections.reject(&:inflight?)
connections.each(&:close)
next_tick until connections.none? { |c| c.state != :idle && @connections.include?(c) }
@resolvers.each_value do |resolver|
resolver.close unless resolver.closed?
end if @connections.empty?
# close resolvers
outstanding_connections = @connections
resolver_connections = @resolvers.each_value.flat_map(&:connections).compact
outstanding_connections -= resolver_connections
if outstanding_connections.empty?
@resolvers.each_value do |resolver|
resolver.close unless resolver.closed?
end
# for https resolver
resolver_connections.each(&:close)
next_tick until resolver_connections.none? { |c| c.state != :idle && @connections.include?(c) }
end
end
def init_connection(connection, _options)

View File

@ -35,6 +35,10 @@ module HTTPX
@resolvers.each(&:close)
end
def connections
@resolvers.filter_map { |r| r.resolver_connection if r.respond_to?(:resolver_connection) }
end
private
def on_resolver_connection(connection)

View File

@ -22,6 +22,10 @@ module HTTPX
@resolver.timeouts = timeouts || Resolver::RESOLVE_TIMEOUT
end
def connections
EMPTY
end
def <<(connection)
hostname = connection.origin.host
addresses = connection.addresses ||

View File

@ -2,8 +2,6 @@ module HTTPX
class Headers
include _ToS
EMPTY: Array[untyped]
@headers: Hash[String, Array[String]]
def self.new: (?untyped headers) -> instance

View File

@ -1,6 +1,8 @@
module HTTPX
extend Chainable
EMPTY: Array[untyped]
VERSION: String
type uri = URI::HTTP | URI::HTTPS | string