Repository navigation
fix(client): unrestricted Swoole clients leave name resolution to Swoole - #14066
Conversation
The Swoole adapter resolved every hostname itself so it could dial an address its Destinations allow. With Anywhere, the default, there is nothing to check, so that only changed how every unrestricted client resolves names: two getaddrinfo() lookups per new connection instead of Swoole's own resolver. Where a lookup falls through the search domains to a slow upstream, a request to a missing service waited out the connect timeout instead of failing at once. An Anywhere client now passes the hostname to Swoole, as it did before Destinations existed, and reconnects the same way. Restricted clients still resolve, check and dial an allowed address. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@hansi-codes review |
🟢 Tier S · Ready to merge
Unrestricted Swoole clients now leave hostname resolution to Swoole, while restricted clients retain address resolution and destination checks. The change also handles bare IPv6 literals and adds an IPv6-only hostname fallback that reuses the prepared request body and remaining connect-timeout budget. New tests cover native hostname resolution, IPv6 connectivity, and one-shot request bodies.
📂 Walkthrough · 3
Reviewed |
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
A URI's host keeps the brackets of an IPv6 literal, and Swoole fails to resolve "[::1]". Strip them for the dial address; the Host header keeps them. A contract test connects both adapters to an IPv6 listener. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@hansi-codes review |
Swoole opens an IPv4 socket for a hostname, so leaving resolution to it fails for a name with only an AAAA record. When the native lookup fails, and only then, ask Swoole's resolver for the IPv6 address and run the exchange once more against it. A name that resolves pays nothing, and a missing name fails as fast as it does natively. A pooled connection built from an address rather than the hostname is rebuilt when it has to reconnect, whatever the destinations. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@hansi-codes review |
The retry started a fresh connect budget, so a slow failed lookup plus the IPv6 connect could exceed the configured timeout. It now carries the first attempt's start time. The IPv6-only hostname test skips without IPv6 loopback, and asserts the response rather than the order Swoole's resolver sends its queries in. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@hansi-codes review |
The request is prepared once and both attempts send it, so a body that can only be read once still arrives. The resolver tests share one fixture, cover the plain IPv4 path, and no longer wait on a fixed delay. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@hansi-codes review |
…er fixture Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@hansi-codes review |
What does this PR do?
Follow-up to #13998. It fixes a regression that PR introduced in the Swoole HTTP adapter: clients with no destination restriction started resolving hostnames themselves, which made a failed lookup slow.
The problem
#13998 gave every client
Destinations. To enforce them, the Swoole adapter resolves the hostname itself (getaddrinfo()for A and AAAA), checks the addresses, and dials one that is allowed. It did that for every client, includingAnywhere, the default, where there is nothing to check.So every unrestricted Swoole client (the geo client, the pooled internal clients) got a different resolution path for no benefit: two
getaddrinfo()lookups per new connection instead of Swoole's own resolver.The cost shows up where a failed lookup is slow. In a cluster whose lookups fall through the search domains to a slow upstream resolver, a request to a service that isn't deployed waited out the connect timeout instead of failing at once. A downstream build that calls a geo service on every request never passed its startup probe, because each health check took the full 5 seconds.
The fix
An
Anywhereclient hands the hostname straight to Swoole, as it did beforeDestinationsexisted, and reconnects the same way. Restricted clients are unchanged: they still resolve, check and dial an allowed address.Two things the adapter's own resolution used to do for IPv6 are kept on the unrestricted path:
Test Plan
bin/monorepo check clientpasses (Rector, Pint, PHPStan).testItRecoversWhenAReusedConnectionIsDropped(Swoole), which is flaky onmaintoo.testItConnectsToAnIpv6Literal(both adapters).testItLeavesAHostnameForSwooleToResolve: requests a name that exists only in the resolver Swoole is configured with. Putting the eagergetaddrinfo()back fails it withCould not resolve host.testItConnectsToAHostnameWithOnlyAnIpv6Address.testItSendsAOneShotBodyToAHostnameWithOnlyAnIpv6Address: posts a body that yields its bytes once and asserts the server received them.getaddrinfo()took 22 ms and 18 ms for the two families, and Swoole's own client failed in 10 ms. Both are fast there, so the stall depends on the cluster's upstream DNS.🤖 Generated with Claude Code