Repository navigation
Conversation
aiohttp[speedups] installs aiodns, so aiohttp's default resolver is c-ares. c-ares caches NXDOMAIN in-process for the SOA negative TTL, up to an hour. A backend whose hostname did not resolve on the router's first attempt can therefore keep failing with a connection error after DNS answers, until the cached entry expires or the router restarts. One example is a Docker Compose service that starts after the router. Use aiohttp.ThreadedResolver for the shared backend session. It resolves with the system getaddrinfo instead of the additional c-ares query cache. System or upstream DNS caching still applies, and aiohttp's successful-lookup cache (ttl_dns_cache, 10 s) is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Mazyad Alabduljaleel <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request configures the AiohttpClientWrapper to use aiohttp.ThreadedResolver instead of the default resolver, preventing failed DNS lookups from being cached and ensuring newly created backends are reachable. A test case is also introduced to verify this behavior. The feedback suggests refactoring the test's setup and teardown logic using nested try...finally blocks to prevent resource leaks and avoid masking exceptions if initialization fails.
| await runner.setup() | ||
| await web.TCPSite(runner, "127.0.0.1", 0).start() | ||
| url = f"http://vllm-worker.invalid:{runner.addresses[0][1]}/health" | ||
|
|
||
| real_getaddrinfo = socket.getaddrinfo | ||
| service_exists = False | ||
|
|
||
| def getaddrinfo(host, *args, **kwargs): | ||
| if host == "vllm-worker.invalid": | ||
| if not service_exists: | ||
| raise socket.gaierror(socket.EAI_NONAME, "Name or service not known") | ||
| host = "127.0.0.1" | ||
| return real_getaddrinfo(host, *args, **kwargs) | ||
|
|
||
| monkeypatch.setattr(socket, "getaddrinfo", getaddrinfo) | ||
| wrapper = AiohttpClientWrapper() | ||
| wrapper.start() | ||
| try: | ||
| with pytest.raises(aiohttp.ClientConnectorDNSError): | ||
| async with wrapper().get(url): | ||
| pass | ||
|
|
||
| service_exists = True | ||
| async with wrapper().get(url) as response: | ||
| assert response.status == 200 | ||
| finally: | ||
| await wrapper.stop() | ||
| await runner.cleanup() |
There was a problem hiding this comment.
If web.TCPSite.start() or any other setup step fails before the try block is entered, runner.cleanup() will not be called, potentially leaking the runner resources. Additionally, if wrapper.start() fails or is not reached, calling wrapper.stop() in the finally block will raise an AttributeError because wrapper.async_client is None, masking the original exception.
Using nested try...finally blocks ensures that both the runner and the client wrapper are safely and independently cleaned up only if their respective initialization succeeded.
await runner.setup()
try:
await web.TCPSite(runner, "127.0.0.1", 0).start()
url = f"http://vllm-worker.invalid:{runner.addresses[0][1]}/health"
real_getaddrinfo = socket.getaddrinfo
service_exists = False
def getaddrinfo(host, *args, **kwargs):
if host == "vllm-worker.invalid":
if not service_exists:
raise socket.gaierror(socket.EAI_NONAME, "Name or service not known")
host = "127.0.0.1"
return real_getaddrinfo(host, *args, **kwargs)
monkeypatch.setattr(socket, "getaddrinfo", getaddrinfo)
wrapper = AiohttpClientWrapper()
wrapper.start()
try:
with pytest.raises(aiohttp.ClientConnectorDNSError):
async with wrapper().get(url):
pass
service_exists = True
async with wrapper().get(url) as response:
assert response.status == 200
finally:
await wrapper.stop()
finally:
await runner.cleanup()There was a problem hiding this comment.
Addressed in 1c3a483: the test server is now released even if a later setup step fails. wrapper.start() already ran before the inner try, so stop() couldn't hide an earlier error, but the nesting makes the cleanup order explicit.
Address review feedback: release the test HTTP server even if a later setup step fails. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Mazyad Alabduljaleel <[email protected]>
…laybook Point the single-label hostname patch at upstream PR vllm-project#1154, which superseded the now-closed vllm-project#737. Record that the DNS resolver change is proposed upstream for the shared client only (vllm-project#1161/vllm-project#1162), and that upstream vllm-project#1164's 503 must not replace the fork's documented 502 envelope on a refresh. Add the evidence-based playbook for getting fixes merged upstream. Docs only; does not trigger an image release. Standard pre-commit hooks pass on the changed files. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01A5cnah4yC2sS7LEZ8mdrTd Signed-off-by: ci-sim <ci@sim>
|
Hi @ruizhang0101, could you take a look when you have a chance? I fixed the test cleanup from review. We’ve been using the resolver change in our fork since October. Thanks! |
|
Status update: this still merges cleanly onto current main ( |
FIX #1161
The shared backend session used aiohttp's default resolver, which is c-ares when aiodns is installed through
aiohttp[speedups]. c-ares keeps a cached NXDOMAIN for the SOA negative TTL (up to an hour), so a backend whose name resolved only after the router's first lookup could stay unreachable for that long. Details and a standalone repro are in the issue.This PR passes
aiohttp.ThreadedResolver()to the shared session's connector: a one-line change plus a comment.getaddrinfoand skips the extra c-ares query cache. Caching in the system or upstream DNS can still delay recovery.ClientConnectorDNSError), and thespeedupsextra are unchanged. Lookups run in the event loop's executor.Testing:
src/tests/test_aiohttp_client.pypatchessocket.getaddrinfoto fail and then succeed, and checks that the shared client reaches a local server on the second request. It fails on main, where c-ares never consultsgetaddrinfo, and passes with this change.ruff checkpass.-swhen doinggit commit[Bugfix],[Feat], and[CI].