43 Commits

Author SHA1 Message Date
HoneyryderChuck
8009fc11b7 native resolver: refactored retries to use timer intervals
there were a lot of issues with bookkeeping this at the connection level; in the end, the timers infra was a much better proxy for all of this; set timer after write; cancel it on reading data to parse
2025-02-28 18:37:05 +00:00
HoneyryderChuck
f76be1983b native resolver: fix stalled resolution on multiple requests to multiple origins
continue resolving when an error happens by immediately writing to the buffer afterwards
2025-02-18 08:13:47 +00:00
HoneyryderChuck
3afe853517 make #early_resolve return a boolean, instead of undefined across implementations 2024-12-10 15:09:00 +00:00
HoneyryderChuck
11d197ff24 changed internal session structure, so that it uses local selectors directly
pools are then used only to fetch new conenctions; selectors are discarded when not needed anymore; HTTPX.wrap is for now patched, but would ideally be done with in the future
2024-11-19 12:55:44 +00:00
HoneyryderChuck
83b4c73b92 protect against coalescing connections on the resolver
these could take connections out of the loop, thereby causinng a busy loop, on multiple request scenarios
2024-08-19 16:45:55 +01:00
HoneyryderChuck
b686119a6f do not try to cast to Options all the time, trust the internal structure 2024-06-11 18:23:12 +01:00
HoneyryderChuck
587271ff77 improving sigs 2024-06-11 18:21:22 +01:00
HoneyryderChuck
2d6fde2e5d downgrade to udp when retrying dns queries 2024-06-11 16:27:51 +01:00
HoneyryderChuck
b32f936365 Merge branch 'issue-250' into 'master'
ssrf filter plugin

Closes #250

See merge request os85/httpx!291
2023-12-02 00:04:38 +00:00
HoneyryderChuck
6106f5cd43 allow early resolve errors to bubble up the session just like lack of nameserver 2023-11-17 23:39:59 +00:00
HoneyryderChuck
ce7eb0b91a out with eden connections, keep closed around
connection bookkeeping on the pool changes, where all conections are kept around, even the ones that close during the scope of the requests; new requests may then find them, reset them, an reselect them. this is a major improvement, as objects get more reused, so less gc and object movement. this also changes the way pool terminates, as connections nonw follow a termination protocol, instead of just closing (which they can while scope is open)
2023-11-15 10:37:38 +00:00
HoneyryderChuck
8bd4dc1fbd fix timers overhead causing spurious wakeups on the select loop
the change to read/write cancellation-driven timeouts as the default
timeout strategy revealed a performance regression; because these were
built on Timers, which never got unsubscribed, this meant that they were
kept beyond the duration of the request they were created for, and
needlessly got picked up for the next timeout tick.

This was fixed by adding a callback on timer intervals, which
unsubscribes them from the timer group when called; these would then be
activated after the timeout is not needed anymore (request send /
response received), thereby removing the overhead on subsequent
requests.

An additional intervals array is also kept in the connection itself;
timeouts from timers are signalled via socket wait calls, however they
were always resulting in timeouts, even when they shouldn't (ex: expect
timeout and send full response payload as a result), and with the wrong
exception class in some cases. By keeping intervals from its requests
around, and monitoring whether there are relevant request triggers, the
connection can therefore handle a timeout or bail out (so that timers
can fire the correct callback).
2023-10-24 22:53:22 +01:00
HoneyryderChuck
d55bfec80c fix: system resolv timeout raise ResolveTimeoutError instead of ResolveError 2023-09-20 17:57:41 +01:00
HoneyryderChuck
c0afc295a5 fix bug in DoH impl when the request returned no answer (Closes #246) 2023-09-14 13:32:04 +01:00
HoneyryderChuck
ee6c5b231f fix for multi-hostname resolution with aliases failing
context of the multiple alias hops was cleaned up from the context,
which broke next query access.
2023-06-29 17:48:59 +01:00
HoneyryderChuck
1475f9a2ec fix for happy eyeballs with early-resolved IPs
for instance, in multi-homed networks, ´/etc/hosts` will have both
    "127.0.0.1" and "::1" pointing from localhost; still only one of
    them may be reachable, if a server binds only to "127.0.0.1", for
    exammple. In such cases, the early exit placed to prevent the loop
    from b0777c61e was preventing the dual-stack IP resolve to pass the
    second set of responses, thereby potentiallly making only the
    unreachable IP accessible to the connection.
2023-06-12 20:10:27 +01:00
HoneyryderChuck
387798fc1a refining soomme signatures 2023-04-26 23:05:45 +01:00
HoneyryderChuck
55d9139a59 native resolver: clean up candidate queries
dns resolution puts candidate queries in the pipeline, in case the first
one misses, but it wasn't cleaning them up in all situations.
2023-04-25 22:46:54 +01:00
HoneyryderChuck
d699526ec2 updated signatures of IO objects 2023-04-25 22:46:54 +01:00
HoneyryderChuck
6aacc9b0eb native resolver falls back to tcp dns when receiving truncated packet
yet another compliance fix for the DNS protocol; while udp is the
preferred transport, in case a truncated response is received, the
resolver will switch to tcp, and performm the DNS query again.

This introduces a new resolver option, `:socket_type`, which is `:udp`
by default.
2023-04-25 22:46:54 +01:00
HoneyryderChuck
a218463c73 Merge branch 'fix-for-dns-candidate-queries' into 'master'
fix: native resolver only tries candidate names when server indicates

See merge request os85/httpx!236
2023-01-21 17:11:26 +00:00
HoneyryderChuck
af261006a3 fix: native resolver only tries candidate names when server indicates
domain not found

since httpx supports candidate calculations for dns queries, candidates
were always traversed when no answers were back. However, the DNS
message response contains a code set by the server, indicating whether
we should consider the domain existing **but** has no adderss, and
unexisting; candidates should only be queried in the latter.
2023-01-21 16:52:25 +00:00
HoneyryderChuck
a5101870a5 fix for Happy Eyeballs v2 on failed connection
Implemementing the following fixes:

* connections are now marked by IP family of the IO;
* connection "mergeable" status dependent on matching origin when conn
  is already open;
* on a connection error, in case it happened while connection, an event
  is emitted, rather than handling it; if there is another connection
  for the same origin still doing the handshake, the error is ignored;
  if not, the error is handled;
* a new event, `:tcp_open`, is emitted when the tcp socket conn is
  established; this allows for concurrent handshakes to be promptly
  terminated, instead of being dependent on TLS handshake;
* connection cloning now happens early, as connection is set for
  resolving; this way, 2-way callbacks are set as early as possible;
2023-01-21 00:51:03 +00:00
HoneyryderChuck
8f8febc10e sig fixes 2022-08-08 22:19:20 +01:00
HoneyryderChuck
71cb66e287 added missing options sig 2022-08-07 14:43:29 +01:00
HoneyryderChuck
6c911768fe fixing selector timeout errors closing all connections and ignoring
resolvers

All kinds of errors happening during the select loop, will be handled as
abrupt select loop errors, and terminate all connections; this also
includes timmeout errors. This is not ideal, for some reasons:
connection timeout errors happening on the loop close all connections,
although it may be only triggered for one (or a subset of) connection
for which the timeout should trigger; second, errors on the DS channel
propagate errors to connections indirectly (the emission mentioned
above), wrongly (connections for different hostnames not yet queried,
will also fail with timeout), and won't clean the resolver state (so
subsequent queries will be done for the same hostname which failed in
the first place).

This fix is a first step to solving this problem. It does not totally
address the first, but i'll fix dealing with errors from the second
use-case.
2022-06-22 02:09:26 +03:00
HoneyryderChuck
64f8ebcf51 exposing original hostname in errors when there's a dns error in a candidate name for resolution 2022-03-28 12:51:35 +01:00
HoneyryderChuck
53ee7ae225 native resolver: support resolv.conf search and ndots params 2022-03-20 02:25:39 +00:00
HoneyryderChuck
c989a14435 native resolver fix: do not signal interests when there's nothing to do (was generating bursty IO) 2022-03-06 15:40:48 +00:00
HoneyryderChuck
6f7f7933c3 proc no lambda 2022-01-17 00:59:01 +02:00
HoneyryderChuck
037994514b reworked early_resolve to work with dual-stack
for multi-backed resolvers, resolving is attempted before sending it to
    the resolver. in this way, cached, local or ip resolves get
    propagated to the proper resolver by ip family, instead of the
    previous mess.

    the system resolver doesn't do these shenanigans (trust getaddrinfo)
2022-01-17 00:56:09 +02:00
HoneyryderChuck
554957f6ca initial reimplementation of the system resolver, now using getaddrinfo
the ruby `resolver` library does everthing in ruby, and sequentially
(first ipv4 then ipv6 resolution). we already have native for that, and
getaddrinfo should be considered the ideal way to use DNS (potentially
in the future, it becomes the default resolver).
2022-01-16 22:54:56 +02:00
HoneyryderChuck
2940323412 implemented happy eyeballs v2 (rfc8305) for native and https resolver
Two resolver are kept (IPv6/IPv4) along in the pool, to which all
names are sent to and read from in the same pool. IPv4 resolves are
subject to a 50ms delay (as per rfc) before they're used for connecting.
IPv6 addresses have preference, in that if they arrive before the delay,
they are immediately used. If they arrive after the delay, they do not
interrupt the connection, but they'll be the next-in-line in case
connection handshake fails.

Two resolvers are kept, but the inherent Connection will be shared,
thereby sending name resolving requests to the same HTTP/2 connection in
bulk. The resolution delay logic from above also applies.

Currently handles resolving via `resolv` lib. This happens synchronously
though, so we're not there yet.
2022-01-16 22:54:56 +02:00
HoneyryderChuck
06b162b6ea applying a resolver manager to hold the different family type resolvers for the pool. This allows to have multiple resolvers per type, i.e. IPv6 and IPv4 2022-01-16 22:54:56 +02:00
HoneyryderChuck
71920157f4 fix: ensuring that the https resolver is using the pool it's being created in 2022-01-16 22:54:56 +02:00
HoneyryderChuck
9bd73e5a22 removing uncaching of resolved names (not used anywhere) 2022-01-16 22:54:54 +02:00
HoneyryderChuck
a8830681df changing resolver structure to rely on inheritance, which helps with typing 2022-01-16 22:53:36 +02:00
HoneyryderChuck
81a41d889c bugfix: remove connections from selector which have been unregistered
during interest calculation

A quirk was found whereby a connection which failed while connecting
(such as the badssl test) was properly unregistered from the pool, was
however kept in the selectables selector pool, because if this operation
happening during the interest calculation pool, and the var substitution
being performed right afterwards, leaving the pool and selector out of
sync and causing all sorts of miscalculations around timers later on.
2021-09-22 12:53:33 +01:00
HoneyryderChuck
6b61b8ccdb fixing signatures
also adding some checks on code, in order for steep to stop complaining
about potential nil returns.
2021-08-10 10:28:58 +01:00
HoneyryderChuck
b6ee019014 several signature improvements while testing with steep 2021-07-07 19:21:36 +01:00
HoneyryderChuck
d6465ce433 by passing arity to curry calls, methods can be type-checked now 2020-12-19 00:26:05 +00:00
HoneyryderChuck
7ba354bcac typing the resolvers 2020-12-09 14:27:27 +00:00
HoneyryderChuck
7bd9f9a33f typing the connection pool 2020-12-08 16:47:39 +00:00