42 Commits

Author SHA1 Message Date
HoneyryderChuck
134bef69e0 removed overrides and refinements of methods prior to 2.7 2023-09-20 17:57:05 +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
edc2c4e6c4 do not loop forever if there are no connections to listen nor any timer
to wait for.

Timeout calculation may trigger errors which lead to connection
unregistering, such as tital timeout errors. In such a case, we can end
up in a state where #select gets called with no timeout and no
selectable connections.

https://github.com/HoneyryderChuck/httpx/issues/3
2021-12-09 15:02:32 +00:00
HoneyryderChuck
efddd72caa removing persistent connections from the selector whe inactive
keeping them around was resulting in some busy loops on timer events
(i.e. retry after), making them unreliable, innacurate  and CPU
draining. they're now kept out whenever they're inactive.
2021-09-27 16:18:02 +01: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
d350bebe81 integrating .sum and .filter_map + backports 2021-09-04 15:25:14 +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
08fa918537 initializing error classes more conventionally 2021-07-07 12:45:14 +01:00
HoneyryderChuck
793f034a91 bugfix: selectables reassignment must ensure it remains an array of IO
objects
2021-07-04 23:42:53 +01:00
HoneyryderChuck
0216a7eed7 improve selector loops 2021-07-01 14:04:47 +03:00
HoneyryderChuck
1907a00d19 fixing the select loop: when closed selectables are discarded, one has to reselect them from start, otherwise it's a loop 2021-05-31 13:29:11 +01:00
HoneyryderChuck
a050b5a403 selector: jump out of the loop if there's nothing to wait on 2021-02-19 17:13:19 +00:00
HoneyryderChuck
b2dff40839 reraise IOError on yield of io, when the error doesn't involve the
client io specifically.

This was the case for multipart tests raising IOErrors on upload files
instead of IO, which was causing the loop to break.
2021-01-14 00:37:00 +00:00
HoneyryderChuck
6fbd8da838 simplified refined IO#wait, as it's designed for a certain niche feature 2020-12-02 01:30:38 +00:00
HoneyryderChuck
1b26977d16 updated rubocop to 1.0.0 on possible rubies, making the necessary changes 2020-11-07 15:36:21 +00:00
HoneyryderChuck
019b41a70c removed the nodocs 2020-10-03 00:28:17 +01:00
HoneyryderChuck
24f1b1426f deleting io monitor (not needed) 2020-04-23 00:39:01 +01:00
HoneyryderChuck
ec6e39d7b9 remove connect call from selector, making it implicit when selecting interests 2020-04-23 00:39:01 +01:00
HoneyryderChuck
93e30f0abf connection: connect before select
a refactoring was performed on the connection, so they could connect out
of the #to_io call; in order to proper read the interests, it was
thought that it was too late at that point, as interests before #to_io
would be different from post #to_io; this makes our selector less
"portable", as we rely on internal logic being called now
2020-04-18 14:53:04 +01:00
HoneyryderChuck
ee49b47dab reenabling select for all rubies; refined waiting for reads and writes simultaneously on one IO 2020-04-13 23:23:00 +01:00
HoneyryderChuck
dc07b50466 moved back to read-write for ssl negotiation, until we have the loop figured out 2020-04-13 22:56:30 +01:00
HoneyryderChuck
5595a6c79f remove unused #close method for selector 2020-04-13 15:23:20 +01:00
HoneyryderChuck
4997548d95 do not use the select_one variant for ruby 2.1, as there is a deadlock on ssl connect that is triggered in a test 2020-04-13 15:23:20 +01:00
HoneyryderChuck
ed23525daf selector: use poll when possible, instead of IO.select
Using IO.select is costly for the one-request/one-origin case, as we
have to build array to pass, and we receive arrays, and that generates a
lot of needless garbage when we only request once. Instead, it now uses
IO#wait_readable and IO#wait_writable, which does not require extra
arrays, and uses poll under the hood.
2020-04-12 03:32:04 +01:00
HoneyryderChuck
de773f6885 removing needless pipes on selector (wakeup sockets are necessary only for the server case) 2020-04-12 03:32:04 +01:00
HoneyryderChuck
9d6f31d940 calculate interests down to connection and parser
by analyzing all of the data down to the parser, one can estimate better
whether io wants to read/write/both, thereby avoiding spurious wakeups.

This also greatly simplifies the monitor API, and solves the 100% CPU
utilization issue.
2020-04-12 03:32:04 +01:00
HoneyryderChuck
be39f6b901 making the selector closer to the nio4r pure ruby selector
Some requests were hanging because some connection with read interests
were only on the writers selector. This issue manifested itself in high
load scenarios.

The fix is not the most performant, but it does the job: only set write
interest when connecting, otherwise read/write. This increases the
number of wakeups, but at least we have correctness.
2019-09-27 20:14:43 +01:00
HoneyryderChuck
2da56ce9af fix: keep connection alive if HTTP/1.1 and there is connection-related
header;

this was wrongly closing connections for HTTP/1.1 connections which
didn't send a "Connection" header; according to spec, the default is
"Keep-Alive", contrary to HTTP/1.0
2019-05-15 14:45:06 +00:00
HoneyryderChuck
ae859f743f request exposes options: this allows responses to be created with the proper set of options, instead of the connection options, which is wrong 2019-05-06 11:56:11 +00:00
HoneyryderChuck
622188c0ab updated rubocop, added a few changes... 2018-12-28 02:44:43 +00:00
HoneyryderChuck
38e00d219f moved connection timeout counting to the channel; the timeout error also contains the interval that timed out; the bookkeeping is therefore kept by each channel 2018-11-22 18:07:45 +00:00
HoneyryderChuck
dcd2709e41 Non-Blocking DNS 2018-08-29 10:23:08 +00:00
HoneyryderChuck
2557eae5f7 connection close: basing on channels to know whether to execute next tick 2018-03-11 00:41:16 +00:00
HoneyryderChuck
1cbec1b959 calling close on parse triggers the channel close; this will eventually trigger its callback (close is not immediate) 2018-02-24 00:06:01 +00:00
HoneyryderChuck
273cdd45b5 rubocoped 2018-02-13 22:19:05 +00:00
HoneyryderChuck
930e654b51 remove selectors which don't have any interest 2018-02-08 23:55:48 +00:00
HoneyryderChuck
2b1ab8b6b6 rubocop auto-corrections according to some basic rules for now 2018-01-28 22:33:41 +00:00
HoneyryderChuck
3807688c61 added IO module to register IO types; now one needs to explicitly call ::IO for top-level 2017-12-22 09:54:35 +02:00
HoneyryderChuck
117acfb6f7 dealt with the timeouts: removed the deadcode for connects, as they no longer proxy it; instead, the selector commands whether the timeout will be triggered, if there are no ready fds; the global handler can also trigger a separate timeout, if this is asked for after the interval was starved, signaling incompletion 2017-12-12 23:58:42 +00:00
HoneyryderChuck
4a9714df3c using requires of core modules everywhere it is used 2017-12-10 20:38:03 +00:00
HoneyryderChuck
2b266d305d selector: don't forget to deregister the writer monitor 2017-12-07 21:11:50 +00:00
HoneyryderChuck
5bbc15528e added proper selector/monitor, replaced where necessary 2017-11-29 18:50:47 +00:00