Class: HTTPX::Resolver::System
- Inherits:
-
Resolver
show all
- Defined in:
- lib/httpx/resolver/system.rb,
sig/resolver/system.rbs
Overview
Implementation of a synchronous name resolver which relies on the system resolver,
which is lib'c getaddrinfo function (abstracted in ruby via Addrinfo.getaddrinfo).
Its main advantage is relying on the reference implementation for name resolution
across most/all OSs which deploy ruby (it's what TCPSocket also uses), its main
disadvantage is the inability to set timeouts / check socket for readiness events,
hence why it relies on using the Timeout module, which poses a lot of problems for
the selector loop, specially when network is unstable.
Defined Under Namespace
Classes: AddrinfoTimeoutError
Constant Summary
collapse
- RESOLV_ERRORS =
[Resolv::ResolvError,
Resolv::DNS::Requester::RequestError,
Resolv::DNS::EncodeError,
Resolv::DNS::DecodeError].freeze
- DONE =
1
- ERROR =
2
Constants inherited
from Resolver
Resolver::FAMILY_TYPES, Resolver::RECORD_TYPES
Constants included
from Loggable
Loggable::COLORS, Loggable::USE_DEBUG_LOG
Instance Attribute Summary collapse
Attributes inherited from Resolver
#current_selector, #current_session, #family, #options
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Resolver
#each_connection, #emit_addresses, #handle_error, #inflight?, #initial_call, #on_error, #on_io_error
Methods included from Loggable
#log, #log_exception, log_identifiers
#inflight?, #initial_call, #on_error, #on_io_error, #terminate
Constructor Details
#initialize(options) ⇒ System
Returns a new instance of System.
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/httpx/resolver/system.rb', line 37
def initialize(options)
super(0, options)
@resolver_options = @options.resolver_options
resolv_options = @resolver_options.dup
timeouts = resolv_options.delete(:timeouts) || Resolver::RESOLVE_TIMEOUT
@_timeouts = Array(timeouts)
@timeouts = Hash.new { |tims, host| tims[host] = @_timeouts.dup }
resolv_options.delete(:cache)
@queries = []
@ips = []
@pipe_mutex = Thread::Mutex.new
@state = :idle
end
|
Instance Attribute Details
#state ⇒ Symbol
Returns the value of attribute state.
35
36
37
|
# File 'lib/httpx/resolver/system.rb', line 35
def state
@state
end
|
Class Method Details
.multi? ⇒ Boolean
30
31
32
|
# File 'lib/httpx/resolver/system.rb', line 30
def multi?
false
end
|
Instance Method Details
#call ⇒ Object
85
86
87
88
89
90
91
|
# File 'lib/httpx/resolver/system.rb', line 85
def call
case @state
when :open
consume
end
nil
end
|
#close ⇒ Object
65
66
67
|
# File 'lib/httpx/resolver/system.rb', line 65
def close
transition(:closed)
end
|
#closed? ⇒ Boolean
77
78
79
|
# File 'lib/httpx/resolver/system.rb', line 77
def closed?
@state == :closed
end
|
#closed_for_select? ⇒ Boolean
93
94
95
|
# File 'lib/httpx/resolver/system.rb', line 93
def closed_for_select?
@state == :closed
end
|
#early_resolve(_) ⇒ Object
rubocop:disable Naming/PredicateMethod
126
127
128
|
# File 'lib/httpx/resolver/system.rb', line 126
def early_resolve(_, **) false
end
|
#empty? ⇒ Boolean
61
62
63
|
# File 'lib/httpx/resolver/system.rb', line 61
def empty?
@connections.empty?
end
|
#force_close ⇒ Object
69
70
71
72
73
74
75
|
# File 'lib/httpx/resolver/system.rb', line 69
def force_close(*)
close
@queries.clear
@timeouts.clear
@ips.clear
super
end
|
#handle_socket_timeout(interval) ⇒ Object
130
131
132
133
134
135
136
137
138
139
140
141
142
|
# File 'lib/httpx/resolver/system.rb', line 130
def handle_socket_timeout(interval)
error = HTTPX::ResolveTimeoutError.new(interval, "timed out while waiting on select")
error.set_backtrace(caller)
@queries.each do |_, connection| emit_resolve_error(connection, connection.peer.host, error) if @connections.delete(connection)
end
while (connection = @connections.shift)
emit_resolve_error(connection, connection.peer.host, error)
end
close_or_resolve
end
|
#interests ⇒ Object
97
98
99
100
101
|
# File 'lib/httpx/resolver/system.rb', line 97
def interests
return if @queries.empty?
:r
end
|
#lazy_resolve(connection) ⇒ Object
117
118
119
120
121
122
123
124
|
# File 'lib/httpx/resolver/system.rb', line 117
def lazy_resolve(connection)
@connections << connection
resolve
return if empty?
@current_session.select_resolver(self, @current_selector)
end
|
#multi ⇒ Object
57
58
59
|
# File 'lib/httpx/resolver/system.rb', line 57
def multi
self
end
|
#resolvers {|_self| ... } ⇒ Object
51
52
53
54
55
|
# File 'lib/httpx/resolver/system.rb', line 51
def resolvers
return enum_for(__method__) unless block_given?
yield self
end
|
#timeout ⇒ Object
103
104
105
106
107
108
109
110
111
112
113
114
115
|
# File 'lib/httpx/resolver/system.rb', line 103
def timeout
_, connection = @queries.first
return unless connection
timeouts = @timeouts[connection.peer.host]
return if timeouts.empty?
log(level: 2) { "resolver #{FAMILY_TYPES[@record_type]}: next timeout #{timeouts.first} secs... (#{timeouts.size - 1} left)" }
timeouts.first
end
|
#to_io ⇒ Object
81
82
83
|
# File 'lib/httpx/resolver/system.rb', line 81
def to_io
@pipe_read.to_io
end
|