arturobernalg opened a new pull request, #935:
URL: https://github.com/apache/httpcomponents-client/pull/935

   Implements RFC 8305 (Happy Eyeballs v2) connection racing for the Async 
client, in MultihomeIOSessionRequester / MultihomeConnectionInitiator, per the 
architecture agreed on #693.
   
   ## Change
   
   For hosts that resolve to more than one address, connection attempts are 
raced instead of tried strictly sequentially:
   - The first address is tried immediately.
   - - Each subsequent address is tried after a configurable attempt delay 
(default 250ms, per RFC 8305 Section 8) unless an outstanding attempt fails 
first, in which case the next address is tried immediately.
   - - The first successful connection wins the race: every other outstanding 
attempt is cancelled, and any connection that completes after a winner has 
already been decided is closed (CloseMode.IMMEDIATE) rather than leaked.
   - - Exactly one terminal callback (success or aggregated failure) ever 
reaches the caller.
   A single lazily-initialized, process-wide daemon-thread 
ScheduledExecutorService paces the staggered attempts. No per-connection or 
per-request executor is created, and no new generic scheduling infrastructure 
was introduced; the existing reactor and InternalAbstractHttpAsyncClient 
scheduler were evaluated first and found unsuitable (the reactor has no generic 
delayed-callback hook, and the client's own scheduler is constructed after the 
connection manager).
   
   The feature is opt-in and defaults to disabled. When disabled (the default 
everywhere), the sequential connection path is byte-for-byte unchanged from 
before this change. Enabled via new, additive constructor overloads on 
MultihomeIOSessionRequester, MultihomeConnectionInitiator, 
DefaultAsyncClientConnectionOperator, and new 
PoolingAsyncClientConnectionManagerBuilder#setHappyEyeballsEnabled(boolean) / 
#setConnectionAttemptDelay(TimeValue) builder methods.
   
   This PR does not touch RFC 6724 destination address ordering (#778, separate 
and unrelated), TLS/ALPN, HTTP semantics, or the Classic (blocking) client.
   
   ## Tests
   
   New unit tests in MultihomeIOSessionRequesterTest using a FakeScheduler test 
double (captures scheduled stagger tasks instead of waiting on real time, fired 
manually) covering: immediate success on the first address, stall-then-win via 
the stagger, fast failure advancing without waiting for the stagger, a loser 
connection completing late and being closed rather than leaked, all addresses 
failing with aggregated failure, cancellation before/during the race (including 
the pending stagger), late completion after cancellation, a single resolved 
address not racing, the feature being disabled by default even with multiple 
addresses, a configurable delay being honored, and the RFC 8305 Section 8 10ms 
minimum delay being enforced.
   
   The two pre-existing tests in the same file were left unchanged and still 
pass, confirming the disabled (default) path is unaffected.
   
   Ran: mvnw -pl httpclient5 -am test (full module) - all tests pass.
   
   ## Dependency
   
   None. Based directly on upstream master, independent of #778.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to