Commit ac86246
committed
lore-transport: Happy eyeballs strategy for QUIC fallback connections across resolved addresses
Use a Happy Eyeballs strategy (see [RFC8305](https://www.rfc-editor.org/info/rfc8305/)) when the QUIC client connects
to a hostname that resolves to multiple socket addresses.
The client now:
- preserves the resolver's preferred first address family;
- interleaves IPv6 and IPv4 candidates while preserving relative order within each family;
- starts the first address immediately;
- starts subsequent attempts with a 250-millisecond stagger;
- advances immediately when all active attempts fail;
- limits concurrent attempts to 10;
- returns the first successful connection and cancels the remaining attempts.
The existing per-address endpoint setup and final error behavior remain unchanged.
## Why
The previous implementation awaited QUIC addresses sequentially. If
`localhost` resolved to `::1` before `127.0.0.1` while `loreserver` listened on
its default IPv4 address, the IPv6 attempt consumed the full 30-second QUIC idle
timeout before IPv4 was attempted.
This caused commands such as `lore history` to take about 30
seconds because repository initialization had started a background QUIC
pre-warm, even if not required.
Before:
```text
remote_url = "lore://localhost:41337"
real 30.05
```
Using `127.0.0.1` directly completed in `0.08s`, confirming that address
fallback was responsible for the delay.
Closes #27
## Testing
Added unit coverage for:
- IPv6-first and IPv4-first address-family interleaving;
- starting a fallback while the first attempt remains stalled;
- advancing immediately after an attempt fails;
- avoiding fallback when the first address succeeds;
- returning failure when every address fails;
- bounding the number of concurrent attempts.
Verification performed:
```console
cargo +nightly fmt --all -- --check
cargo test -p lore-transport
cargo clippy -p lore-transport --all-targets -- -D warnings --no-deps
```
All 28 `lore-transport` tests pass.
The original reproduction using `lore://localhost:41337` now completes in:
```text
real 0.38
```
A remote immutable-store query also demonstrated the complete fallback:
```text
QUIC connecting to localhost at [::1]:41337
QUIC connecting to localhost at 127.0.0.1:41337
Success QUIC connecting to 127.0.0.1:41337
QUIC connection ... complete in 254ms
real 0.27
```
### Note on tests
The `lore-transport/src/quic/client.rs` file did not contain any test previously,
and if they are wrongly placed, let me know and I'll make amendments.
## Alternative approach
The alternative would be to prevent QUIC from connecting for commands
that do not require QUIC connection. I rejected that solution due to sweeping
changes required.
## AI disclosure
OpenAI GPT-5.5 was used to improve upon the first version of this PR.
CoPilot-generated code review snippets were used to amend the PR with
suggested fixes.
```
Imported-PR: #28
Imported-From: 5afffc2
Imported-Base: 6f14447
Imported-Merge: 8583075
Imported-Author: Andrzej Haczewski (ahaczewski)
Signed-off-by: Andrzej Haczewski <ahaczewski@gmail.com>
GH-URL: #28
```
Lore-RevId: 482
Lore-Signature: a625a714b2e4ada93734f6a98bc5c071191943f6c107e051960c38ea364bf5c71 parent 6f14447 commit ac86246
1 file changed
Lines changed: 351 additions & 64 deletions
0 commit comments