Repository navigation
Conversation
Merging this PR will not alter performance
Comparing Footnotes
|
There was a problem hiding this comment.
1 issue found across 4 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="src/httpcore2/httpcore2/_backends/asyncio.py">
<violation number="1" location="src/httpcore2/httpcore2/_backends/asyncio.py:201">
P2: A hostname `local_address` can force the destination lookup to the resolver's first family and prevent valid connections to the other family. Resolve or bind the local source address per destination-family attempt instead of restricting all remote addresses to the first local result.</violation>
</file>
Reply to a comment to ask cubic a question or push back. It learns from your replies.
View guided diff | Re-trigger cubic
| family: int = socket.AF_UNSPEC | ||
| local_addr = None | ||
| if local_address is not None: | ||
| family, *_, local_addr = (await _getaddrinfo(local_address, 0, socket.AF_UNSPEC))[0] |
There was a problem hiding this comment.
P2: A hostname local_address can force the destination lookup to the resolver's first family and prevent valid connections to the other family. Resolve or bind the local source address per destination-family attempt instead of restricting all remote addresses to the first local result.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At src/httpcore2/httpcore2/_backends/asyncio.py, line 201:
<comment>A hostname `local_address` can force the destination lookup to the resolver's first family and prevent valid connections to the other family. Resolve or bind the local source address per destination-family attempt instead of restricting all remote addresses to the first local result.</comment>
<file context>
@@ -0,0 +1,287 @@
+ family: int = socket.AF_UNSPEC
+ local_addr = None
+ if local_address is not None:
+ family, *_, local_addr = (await _getaddrinfo(local_address, 0, socket.AF_UNSPEC))[0]
+ infos = _interleave_families(await _getaddrinfo(host, port, family))
+
</file context>
There was a problem hiding this comment.
It's the same behavior as in anyio
There was a problem hiding this comment.
@mimi89999 You're right — I verified it, and anyio does exactly this. In anyio._core._sockets.connect_tcp:
family = socket.AF_UNSPEC
if local_host:
gai_res = await getaddrinfo(str(local_host), None)
family, *_, local_address = gai_res[0]
...
gai_res = await getaddrinfo(target_host, remote_port, family=family, ...)Same pattern: resolve the local host with AF_UNSPEC, take the first entry, and restrict the destination lookup to that family. So my comment is too broad for this PR — this backend is meant to be behaviorally equivalent to the default AnyIOBackend, and deviating here would actually make it less consistent with the anyio path. Leaving it as-is is defensible; feel free to resolve the thread. If you wanted, a one-line # same as anyio comment next to that block would save the next reviewer the same investigation.
One tiny nuance if you care: for remote IP literals, anyio bypasses the family restriction entirely (it checks ip_address(remote_host) before getaddrinfo and connects directly), while your _getaddrinfo applies the restricted family to literals too. So a hostname local_address that resolves IPv6-first plus an IPv4-literal destination would connect under anyio but fail here. That's a very narrow corner, and not worth changing if you don't want to — I just mention it so the parity claim is exact.
Tip: get faster answers by chatting with cubic’s review copilot in the review UI
|
Please fix CI. |
857c962 to
acb7a8d
Compare
There was a problem hiding this comment.
All reported issues were addressed across 4 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
acb7a8d to
aaac2bc
Compare
There was a problem hiding this comment.
All reported issues were addressed across 2 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
aaac2bc to
e57fe9c
Compare
There was a problem hiding this comment.
All reported issues were addressed across 2 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
e57fe9c to
18f329d
Compare
|
@Kludex I added tests, fixed the CI and addressed the bot’s findings. I also removed the poll() call from the stale connection check, which brings the 500 idle connections case to -75% vs anyio. |
There was a problem hiding this comment.
All reported issues were addressed across 1 file (changes from recent commits).
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
18f329d to
ad0bab4
Compare
ad0bab4 to
ff0f64d
Compare
ff0f64d to
409c425
Compare
Summary
Adds
httpcore2.AsyncIOBackend, a network backend built directly on asyncio streams, without anyio. It's opt-in for now:AutoBackendstill usesAnyIOBackend.It also does its own happy eyeballs (RFC 8305), so it behaves the same on uvloop, which doesn't support
happy_eyeballs_delay.The stale connection check first looks at what asyncio has already read (EOF, error or buffered data), and only polls the socket if there's nothing there.
Idle connections (time per request, median of 3 rounds, rebased on #1352):
benchmark/run.py --quick(Python 3.14, median of 3 rounds, with a local tweak to pick the backend):Checklist