Skip to content

fix(tests): use .invalid TLD for unresolvable DNS test#12416

Draft
Bojun-Vvibe wants to merge 1 commit intoaio-libs:masterfrom
Bojun-Vvibe:fix/aio-libs-aiohttp-11293
Draft

fix(tests): use .invalid TLD for unresolvable DNS test#12416
Bojun-Vvibe wants to merge 1 commit intoaio-libs:masterfrom
Bojun-Vvibe:fix/aio-libs-aiohttp-11293

Conversation

@Bojun-Vvibe
Copy link
Copy Markdown

Closes #11293

Repo

aio-libs/aiohttp

Issue

#11293

Root cause

test_aiohttp_request_ctx_manager_not_found relied on http://wrong-dns-name.com failing DNS resolution, but on some networks (notably macOS / certain ISPs) that domain can intermittently resolve (NXDOMAIN hijacking, parking pages, cached records). When it resolves, the request proceeds past the async with, the inner assert False trips, and the outer pytest.raises(ClientConnectionError) fails.

Fix

Switch the hostname to wrong-dns-name.invalid, using the reserved .invalid TLD (RFC 2606) which is guaranteed never to resolve. Also added the "never executed" message to the inner assertion to match the sibling test and aid debugging.

Regression test

tests/test_client_functional.py::test_aiohttp_request_ctx_manager_not_found — same test, now deterministic; it asserts that entering an aiohttp.request context manager for an unresolvable host raises ClientConnectionError and never enters the body.

Risk

trivial

Verification

skipped: local pytest env missing required plugins (textual); manually verified via socket.getaddrinfo('wrong-dns-name.invalid', 80) raises gaierror, confirming .invalid is unresolvable and the test will reliably hit the ClientConnectionError path.

test_aiohttp_request_ctx_manager_not_found was flaky on networks where
'wrong-dns-name.com' could occasionally resolve (e.g. ISP NXDOMAIN
hijacking or transient parking entries), causing the request to
proceed and trip the inner assertion. Switch to the reserved .invalid
TLD (RFC 2606), which is guaranteed never to resolve.
@psf-chronographer psf-chronographer Bot added the bot:chronographer:provided There is a change note present in this PR label Apr 23, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 23, 2026

❌ 1 Tests Failed:

Tests completed Failed Passed Skipped
4490 1 4489 73
View the top 1 failed test(s) by shortest run time
tests.test_client_middleware::test_middleware_uses_session_avoids_recursion_with_disabled_middleware[pyloop]
Stack Traces | 2.46s run time
self = <aiohttp.connector.TCPConnector object at 0x000001673FA58B80>
addr_infos = []
req = <aiohttp.client_reqrep.ClientRequest object at 0x000001673FA59C30>
timeout = ClientTimeout(total=300, connect=None, sock_read=None, sock_connect=30, ceil_threshold=5)
client_error = <class 'aiohttp.client_exceptions.ClientConnectorError'>
args = (functools.partial(<class 'aiohttp.client_proto.ResponseHandler'>, loop=<ProactorEventLoop running=False closed=False debug=False>),)
kwargs = {'server_hostname': None, 'ssl': None}

    #x1B[0m#x1B[94masync#x1B[39;49;00m #x1B[94mdef#x1B[39;49;00m#x1B[90m #x1B[39;49;00m#x1B[92m_wrap_create_connection#x1B[39;49;00m(#x1B[90m#x1B[39;49;00m
        #x1B[96mself#x1B[39;49;00m,#x1B[90m#x1B[39;49;00m
        *args: Any,#x1B[90m#x1B[39;49;00m
        addr_infos: #x1B[96mlist#x1B[39;49;00m[AddrInfoType],#x1B[90m#x1B[39;49;00m
        req: ClientRequestBase,#x1B[90m#x1B[39;49;00m
        timeout: #x1B[33m"#x1B[39;49;00m#x1B[33mClientTimeout#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m,#x1B[90m#x1B[39;49;00m
        client_error: #x1B[96mtype#x1B[39;49;00m[#x1B[96mException#x1B[39;49;00m] = ClientConnectorError,#x1B[90m#x1B[39;49;00m
        **kwargs: Any,#x1B[90m#x1B[39;49;00m
    ) -> #x1B[96mtuple#x1B[39;49;00m[asyncio.Transport, ResponseHandler]:#x1B[90m#x1B[39;49;00m
        #x1B[94mtry#x1B[39;49;00m:#x1B[90m#x1B[39;49;00m
            #x1B[94masync#x1B[39;49;00m #x1B[94mwith#x1B[39;49;00m ceil_timeout(#x1B[90m#x1B[39;49;00m
                timeout.sock_connect, ceil_threshold=timeout.ceil_threshold#x1B[90m#x1B[39;49;00m
            ):#x1B[90m#x1B[39;49;00m
>               sock = #x1B[94mawait#x1B[39;49;00m aiohappyeyeballs.start_connection(#x1B[90m#x1B[39;49;00m
                    addr_infos=addr_infos,#x1B[90m#x1B[39;49;00m
                    local_addr_infos=#x1B[96mself#x1B[39;49;00m._local_addr_infos,#x1B[90m#x1B[39;49;00m
                    happy_eyeballs_delay=#x1B[96mself#x1B[39;49;00m._happy_eyeballs_delay,#x1B[90m#x1B[39;49;00m
                    interleave=#x1B[96mself#x1B[39;49;00m._interleave,#x1B[90m#x1B[39;49;00m
                    loop=#x1B[96mself#x1B[39;49;00m._loop,#x1B[90m#x1B[39;49;00m
                    socket_factory=#x1B[96mself#x1B[39;49;00m._socket_factory,#x1B[90m#x1B[39;49;00m
                )#x1B[90m#x1B[39;49;00m

addr_infos = []
args       = (functools.partial(<class 'aiohttp.client_proto.ResponseHandler'>, loop=<ProactorEventLoop running=False closed=False debug=False>),)
client_error = <class 'aiohttp.client_exceptions.ClientConnectorError'>
kwargs     = {'server_hostname': None, 'ssl': None}
req        = <aiohttp.client_reqrep.ClientRequest object at 0x000001673FA59C30>
self       = <aiohttp.connector.TCPConnector object at 0x000001673FA58B80>
timeout    = ClientTimeout(total=300, connect=None, sock_read=None, sock_connect=30, ceil_threshold=5)

#x1B[1m#x1B[31maiohttp\connector.py#x1B[0m:1244: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
#x1B[1m#x1B[31mC:\hostedtoolcache\windows\Python\3.10.11\x64\lib\site-packages\aiohappyeyeballs\impl.py#x1B[0m:127: in start_connection
    #x1B[0m#x1B[94mraise#x1B[39;49;00m first_exception#x1B[90m#x1B[39;49;00m
        _          = [ConnectionRefusedError(22, 'The remote computer refused the network connection', None, 1225, None), ConnectionRefusedError(22, 'The remote computer refused the network connection', None, 1225, None)]
        addr_infos = [(<AddressFamily.AF_INET6: 23>, <SocketKind.SOCK_STREAM: 1>, 6, '', ('::1', 1755, 0, 0)), (<AddressFamily.AF_INET: 2>, <SocketKind.SOCK_STREAM: 1>, 6, '', ('127.0.0.1', 1755))]
        all_exceptions = None
        current_loop = <ProactorEventLoop running=False closed=False debug=False>
        exceptions = None
        first_exception = ConnectionRefusedError(22, 'The remote computer refused the network connection', None, 1225, None)
        happy_eyeballs_delay = 0.25
        interleave = 1
        local_addr_infos = None
        loop       = <ProactorEventLoop running=False closed=False debug=False>
        model      = '[WinError 1225] The remote computer refused the network connection'
        open_sockets = None
        single_addr_info = False
        sock       = None
        socket_factory = None
#x1B[1m#x1B[31mC:\hostedtoolcache\windows\Python\3.10.11\x64\lib\site-packages\aiohappyeyeballs\_staggered.py#x1B[0m:132: in run_one_coro
    #x1B[0mresult = #x1B[94mawait#x1B[39;49;00m coro_fn()#x1B[90m#x1B[39;49;00m
        coro_fn    = functools.partial(<function _connect_sock at 0x000001673D0A75B0>, <ProactorEventLoop running=False closed=False debug=...5, None)]], (<AddressFamily.AF_INET6: 23>, <SocketKind.SOCK_STREAM: 1>, 6, '', ('::1', 1755, 0, 0)), None, set(), None)
        exceptions = [ConnectionRefusedError(22, 'The remote computer refused the network connection', None, 1225, None), ConnectionRefusedError(22, 'The remote computer refused the network connection', None, 1225, None)]
        start_next = <Future finished result=None>
        this_index = 0
#x1B[1m#x1B[31mC:\hostedtoolcache\windows\Python\3.10.11\x64\lib\site-packages\aiohappyeyeballs\impl.py#x1B[0m:208: in _connect_sock
    #x1B[0m#x1B[94mawait#x1B[39;49;00m loop.sock_connect(sock, address)#x1B[90m#x1B[39;49;00m
        _          = ''
        addr_info  = (<AddressFamily.AF_INET6: 23>, <SocketKind.SOCK_STREAM: 1>, 6, '', ('::1', 1755, 0, 0))
        address    = ('::1', 1755, 0, 0)
        exceptions = None
        family     = <AddressFamily.AF_INET6: 23>
        local_addr_infos = None
        loop       = <ProactorEventLoop running=False closed=False debug=False>
        my_exceptions = None
        open_sockets = set()
        proto      = 6
        sock       = <socket.socket [closed] fd=-1, family=AddressFamily.AF_INET6, type=SocketKind.SOCK_STREAM, proto=6>
        socket_factory = None
        type_      = <SocketKind.SOCK_STREAM: 1>
#x1B[1m#x1B[31mC:\hostedtoolcache\windows\Python\3.10.11\x64\lib\asyncio\proactor_events.py#x1B[0m:709: in sock_connect
    #x1B[0m#x1B[94mreturn#x1B[39;49;00m #x1B[94mawait#x1B[39;49;00m #x1B[96mself#x1B[39;49;00m._proactor.connect(sock, address)#x1B[90m#x1B[39;49;00m
        address    = ('::1', 1755, 0, 0)
        self       = <ProactorEventLoop running=False closed=False debug=False>
        sock       = <socket.socket [closed] fd=-1, family=AddressFamily.AF_INET6, type=SocketKind.SOCK_STREAM, proto=6>
#x1B[1m#x1B[31mC:\hostedtoolcache\windows\Python\3.10.11\x64\lib\asyncio\windows_events.py#x1B[0m:826: in _poll
    #x1B[0mvalue = callback(transferred, key, ov)#x1B[90m#x1B[39;49;00m
        address    = 1542974462928
        callback   = <function IocpProactor.connect.<locals>.finish_connect at 0x000001674071C3A0>
        err        = 1225
        f          = None
        key        = 0
        ms         = 0
        obj        = <socket.socket [closed] fd=-1, family=AddressFamily.AF_INET6, type=SocketKind.SOCK_STREAM, proto=6>
        ov         = <_overlapped.Overlapped object at 0x000001674071DBC0>
        self       = <IocpProactor overlapped#=3 result#=0>
        status     = None
        timeout    = 29.610000000000014
        transferred = 0
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

trans = 0, key = 0, ov = <_overlapped.Overlapped object at 0x000001674071DBC0>

    #x1B[0m#x1B[94mdef#x1B[39;49;00m#x1B[90m #x1B[39;49;00m#x1B[92mfinish_connect#x1B[39;49;00m(trans, key, ov):#x1B[90m#x1B[39;49;00m
>       ov.getresult()#x1B[90m#x1B[39;49;00m
#x1B[1m#x1B[31mE       ConnectionRefusedError: [WinError 1225] The remote computer refused the network connection#x1B[0m

conn       = <socket.socket [closed] fd=-1, family=AddressFamily.AF_INET6, type=SocketKind.SOCK_STREAM, proto=6>
key        = 0
ov         = <_overlapped.Overlapped object at 0x000001674071DBC0>
trans      = 0

#x1B[1m#x1B[31mC:\hostedtoolcache\windows\Python\3.10.11\x64\lib\asyncio\windows_events.py#x1B[0m:613: ConnectionRefusedError

#x1B[33mThe above exception was the direct cause of the following exception:#x1B[0m

aiohttp_server = <function aiohttp_server.<locals>.go at 0x000001673FF68B80>

    #x1B[0m#x1B[94masync#x1B[39;49;00m #x1B[94mdef#x1B[39;49;00m#x1B[90m #x1B[39;49;00m#x1B[92mtest_middleware_uses_session_avoids_recursion_with_disabled_middleware#x1B[39;49;00m(#x1B[90m#x1B[39;49;00m
        aiohttp_server: AiohttpServer,#x1B[90m#x1B[39;49;00m
    ) -> #x1B[94mNone#x1B[39;49;00m:#x1B[90m#x1B[39;49;00m
    #x1B[90m    #x1B[39;49;00m#x1B[33m"""Test that middleware can avoid infinite recursion by disabling middleware."""#x1B[39;49;00m#x1B[90m#x1B[39;49;00m
        log_collector: #x1B[96mlist#x1B[39;49;00m[#x1B[96mdict#x1B[39;49;00m[#x1B[96mstr#x1B[39;49;00m, #x1B[96mstr#x1B[39;49;00m]] = []#x1B[90m#x1B[39;49;00m
        request_count = #x1B[94m0#x1B[39;49;00m#x1B[90m#x1B[39;49;00m
    #x1B[90m#x1B[39;49;00m
        #x1B[94masync#x1B[39;49;00m #x1B[94mdef#x1B[39;49;00m#x1B[90m #x1B[39;49;00m#x1B[92mlog_api_handler#x1B[39;49;00m(request: web.Request) -> web.Response:#x1B[90m#x1B[39;49;00m
    #x1B[90m        #x1B[39;49;00m#x1B[33m"""Handle log API requests."""#x1B[39;49;00m#x1B[90m#x1B[39;49;00m
            #x1B[94mnonlocal#x1B[39;49;00m request_count#x1B[90m#x1B[39;49;00m
            request_count += #x1B[94m1#x1B[39;49;00m#x1B[90m#x1B[39;49;00m
            data: #x1B[96mdict#x1B[39;49;00m[#x1B[96mstr#x1B[39;49;00m, #x1B[96mstr#x1B[39;49;00m] = #x1B[94mawait#x1B[39;49;00m request.json()#x1B[90m#x1B[39;49;00m
            log_collector.append(data)#x1B[90m#x1B[39;49;00m
            #x1B[94mreturn#x1B[39;49;00m web.Response(text=#x1B[33m"#x1B[39;49;00m#x1B[33mOK#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m)#x1B[90m#x1B[39;49;00m
    #x1B[90m#x1B[39;49;00m
        #x1B[94masync#x1B[39;49;00m #x1B[94mdef#x1B[39;49;00m#x1B[90m #x1B[39;49;00m#x1B[92mmain_handler#x1B[39;49;00m(request: web.Request) -> web.Response:#x1B[90m#x1B[39;49;00m
    #x1B[90m        #x1B[39;49;00m#x1B[33m"""Handle main server requests."""#x1B[39;49;00m#x1B[90m#x1B[39;49;00m
            #x1B[94mreturn#x1B[39;49;00m web.Response(text=#x1B[33mf#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m#x1B[33mHello from #x1B[39;49;00m#x1B[33m{#x1B[39;49;00mrequest.path#x1B[33m}#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m)#x1B[90m#x1B[39;49;00m
    #x1B[90m#x1B[39;49;00m
        #x1B[90m# Create log API server#x1B[39;49;00m#x1B[90m#x1B[39;49;00m
        log_app = web.Application()#x1B[90m#x1B[39;49;00m
        log_app.router.add_post(#x1B[33m"#x1B[39;49;00m#x1B[33m/log#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m, log_api_handler)#x1B[90m#x1B[39;49;00m
        log_server = #x1B[94mawait#x1B[39;49;00m aiohttp_server(log_app)#x1B[90m#x1B[39;49;00m
    #x1B[90m#x1B[39;49;00m
        #x1B[90m# Create main server#x1B[39;49;00m#x1B[90m#x1B[39;49;00m
        main_app = web.Application()#x1B[90m#x1B[39;49;00m
        main_app.router.add_get(#x1B[33m"#x1B[39;49;00m#x1B[33m/#x1B[39;49;00m#x1B[33m{#x1B[39;49;00m#x1B[33mpath:.*}#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m, main_handler)#x1B[90m#x1B[39;49;00m
        main_server = #x1B[94mawait#x1B[39;49;00m aiohttp_server(main_app)#x1B[90m#x1B[39;49;00m
    #x1B[90m#x1B[39;49;00m
        #x1B[94masync#x1B[39;49;00m #x1B[94mdef#x1B[39;49;00m#x1B[90m #x1B[39;49;00m#x1B[92mlog_middleware#x1B[39;49;00m(#x1B[90m#x1B[39;49;00m
            request: ClientRequest, handler: ClientHandlerType#x1B[90m#x1B[39;49;00m
        ) -> ClientResponse:#x1B[90m#x1B[39;49;00m
    #x1B[90m        #x1B[39;49;00m#x1B[33m"""Log all requests using session with disabled middleware."""#x1B[39;49;00m#x1B[90m#x1B[39;49;00m
            #x1B[90m# Use the session from the request to make the logging call#x1B[39;49;00m#x1B[90m#x1B[39;49;00m
            #x1B[90m# Disable middleware to avoid infinite recursion#x1B[39;49;00m#x1B[90m#x1B[39;49;00m
            #x1B[94masync#x1B[39;49;00m #x1B[94mwith#x1B[39;49;00m request.session.post(#x1B[90m#x1B[39;49;00m
                #x1B[33mf#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m#x1B[33mhttp://localhost:#x1B[39;49;00m#x1B[33m{#x1B[39;49;00mlog_server.port#x1B[33m}#x1B[39;49;00m#x1B[33m/log#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m,#x1B[90m#x1B[39;49;00m
                json={#x1B[33m"#x1B[39;49;00m#x1B[33mmethod#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m: #x1B[96mstr#x1B[39;49;00m(request.method), #x1B[33m"#x1B[39;49;00m#x1B[33murl#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m: #x1B[96mstr#x1B[39;49;00m(request.url)},#x1B[90m#x1B[39;49;00m
                middlewares=(),  #x1B[90m# This prevents infinite recursion#x1B[39;49;00m#x1B[90m#x1B[39;49;00m
            ) #x1B[94mas#x1B[39;49;00m resp:#x1B[90m#x1B[39;49;00m
                #x1B[94massert#x1B[39;49;00m resp.status == #x1B[94m200#x1B[39;49;00m#x1B[90m#x1B[39;49;00m
    #x1B[90m#x1B[39;49;00m
            #x1B[94mreturn#x1B[39;49;00m #x1B[94mawait#x1B[39;49;00m handler(request)#x1B[90m#x1B[39;49;00m
    #x1B[90m#x1B[39;49;00m
        #x1B[90m# Create session with the middleware#x1B[39;49;00m#x1B[90m#x1B[39;49;00m
        #x1B[94masync#x1B[39;49;00m #x1B[94mwith#x1B[39;49;00m ClientSession(middlewares=(log_middleware,)) #x1B[94mas#x1B[39;49;00m session:#x1B[90m#x1B[39;49;00m
            #x1B[90m# Make request to main server - should be logged#x1B[39;49;00m#x1B[90m#x1B[39;49;00m
>           #x1B[94masync#x1B[39;49;00m #x1B[94mwith#x1B[39;49;00m session.get(main_server.make_url(#x1B[33m"#x1B[39;49;00m#x1B[33m/test#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m)) #x1B[94mas#x1B[39;49;00m resp:#x1B[90m#x1B[39;49;00m

aiohttp_server = <function aiohttp_server.<locals>.go at 0x000001673FF68B80>
log_api_handler = <function test_middleware_uses_session_avoids_recursion_with_disabled_middleware.<locals>.log_api_handler at 0x00000167401375B0>
log_app    = <Application 0x167406f6770>
log_collector = []
log_middleware = <function test_middleware_uses_session_avoids_recursion_with_disabled_middleware.<locals>.log_middleware at 0x000001673F6527A0>
log_server = <aiohttp.test_utils.TestServer object at 0x000001673FA5A170>
main_app   = <Application 0x167406f7b60>
main_handler = <function test_middleware_uses_session_avoids_recursion_with_disabled_middleware.<locals>.main_handler at 0x000001673FF6A0E0>
main_server = <aiohttp.test_utils.TestServer object at 0x000001673FA5BE20>
request_count = 0
session    = <aiohttp.client.ClientSession object at 0x00000167407203A0>

#x1B[1m#x1B[31mtests\test_client_middleware.py#x1B[0m:1037: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
#x1B[1m#x1B[31maiohttp\client.py#x1B[0m:1534: in __aenter__
    #x1B[0m#x1B[96mself#x1B[39;49;00m._resp: _RetType_co = #x1B[94mawait#x1B[39;49;00m #x1B[96mself#x1B[39;49;00m._coro#x1B[90m#x1B[39;49;00m
        self       = <aiohttp.client._BaseRequestContextManager object at 0x000001673FA58370>
#x1B[1m#x1B[31maiohttp\client.py#x1B[0m:769: in _request
    #x1B[0mresp = #x1B[94mawait#x1B[39;49;00m handler(req)#x1B[90m#x1B[39;49;00m
        _connect_and_send_request = <function ClientSession._request.<locals>._connect_and_send_request at 0x000001673F651C60>
        all_cookies = <BaseCookie: >
        allow_redirects = True
        auth       = None
        auth_from_url = None
        auto_decompress = True
        chunked    = None
        compress   = False
        cookies    = None
        data       = None
        effective_middlewares = (<function test_middleware_uses_session_avoids_recursion_with_disabled_middleware.<locals>.log_middleware at 0x000001673F6527A0>,)
        expect100  = False
        handle     = None
        handler    = <function build_client_middlewares.<locals>.single_middleware_handler at 0x000001674071E050>
        headers    = <CIMultiDict()>
        history    = []
        json       = None
        max_field_size = 8190
        max_headers = 128
        max_line_size = 8190
        max_redirects = 10
        method     = 'GET'
        middlewares = None
        params     = {}
        proxy      = None
        proxy_     = None
        proxy_auth = None
        proxy_headers = None
        raise_for_status = None
        read_bufsize = 262144
        read_until_eof = True
        real_timeout = ClientTimeout(total=300, connect=None, sock_read=None, sock_connect=30, ceil_threshold=5)
        redirects  = 0
        req        = <aiohttp.client_reqrep.ClientRequest object at 0x000001673FA5BCD0>
        retry_persistent_connection = True
        self       = <aiohttp.client.ClientSession object at 0x00000167407203A0>
        server_hostname = None
        skip_auto_headers = None
        skip_headers = None
        ssl        = True
        str_or_url = URL('http://127.0.0.1:56071/test')
        timeout    = <_SENTINEL.sentinel: 1>
        timer      = <aiohttp.helpers.TimerContext object at 0x000001674073DCB0>
        tm         = <aiohttp.helpers.TimeoutHandle object at 0x00000167404C1C80>
        trace_request_ctx = None
        traces     = []
        url        = URL('http://127.0.0.1:56071/test')
        version    = HttpVersion(major=1, minor=1)
#x1B[1m#x1B[31maiohttp\client_middlewares.py#x1B[0m:36: in single_middleware_handler
    #x1B[0m#x1B[94mreturn#x1B[39;49;00m #x1B[94mawait#x1B[39;49;00m middleware(req, handler)#x1B[90m#x1B[39;49;00m
        handler    = <function ClientSession._request.<locals>._connect_and_send_request at 0x000001673F651C60>
        middleware = <function test_middleware_uses_session_avoids_recursion_with_disabled_middleware.<locals>.log_middleware at 0x000001673F6527A0>
        req        = <aiohttp.client_reqrep.ClientRequest object at 0x000001673FA5BCD0>
#x1B[1m#x1B[31mtests\test_client_middleware.py#x1B[0m:1025: in log_middleware
    #x1B[0m#x1B[94masync#x1B[39;49;00m #x1B[94mwith#x1B[39;49;00m request.session.post(#x1B[90m#x1B[39;49;00m
        handler    = <function ClientSession._request.<locals>._connect_and_send_request at 0x000001673F651C60>
        log_server = <aiohttp.test_utils.TestServer object at 0x000001673FA5A170>
        request    = <aiohttp.client_reqrep.ClientRequest object at 0x000001673FA5BCD0>
#x1B[1m#x1B[31maiohttp\client.py#x1B[0m:1534: in __aenter__
    #x1B[0m#x1B[96mself#x1B[39;49;00m._resp: _RetType_co = #x1B[94mawait#x1B[39;49;00m #x1B[96mself#x1B[39;49;00m._coro#x1B[90m#x1B[39;49;00m
        self       = <aiohttp.client._BaseRequestContextManager object at 0x000001673FA58400>
#x1B[1m#x1B[31maiohttp\client.py#x1B[0m:769: in _request
    #x1B[0mresp = #x1B[94mawait#x1B[39;49;00m handler(req)#x1B[90m#x1B[39;49;00m
        _connect_and_send_request = <function ClientSession._request.<locals>._connect_and_send_request at 0x000001674071E0E0>
        all_cookies = <BaseCookie: >
        allow_redirects = True
        auth       = None
        auth_from_url = None
        auto_decompress = True
        chunked    = None
        compress   = False
        cookies    = None
        data       = <aiohttp.payload.JsonPayload object at 0x000001673FA589A0>
        effective_middlewares = ()
        expect100  = False
        handle     = None
        handler    = <function ClientSession._request.<locals>._connect_and_send_request at 0x000001674071E0E0>
        headers    = <CIMultiDict()>
        history    = []
        json       = {'method': 'GET', 'url': 'http://127.0.0.1:56071/test'}
        max_field_size = 8190
        max_headers = 128
        max_line_size = 8190
        max_redirects = 10
        method     = 'POST'
        middlewares = ()
        params     = {}
        proxy      = None
        proxy_     = None
        proxy_auth = None
        proxy_headers = None
        raise_for_status = None
        read_bufsize = 262144
        read_until_eof = True
        real_timeout = ClientTimeout(total=300, connect=None, sock_read=None, sock_connect=30, ceil_threshold=5)
        redirects  = 0
        req        = <aiohttp.client_reqrep.ClientRequest object at 0x000001673FA59C30>
        retry_persistent_connection = False
        self       = <aiohttp.client.ClientSession object at 0x00000167407203A0>
        server_hostname = None
        skip_auto_headers = None
        skip_headers = None
        ssl        = True
        str_or_url = 'http://localhost:56070/log'
        timeout    = <_SENTINEL.sentinel: 1>
        timer      = <aiohttp.helpers.TimerContext object at 0x00000167400C3FB0>
        tm         = <aiohttp.helpers.TimeoutHandle object at 0x00000167404C0300>
        trace_request_ctx = None
        traces     = []
        url        = URL('http://localhost:56070/log')
        version    = HttpVersion(major=1, minor=1)
#x1B[1m#x1B[31maiohttp\client.py#x1B[0m:723: in _connect_and_send_request
    #x1B[0mconn = #x1B[94mawait#x1B[39;49;00m #x1B[96mself#x1B[39;49;00m._connector.connect(#x1B[90m#x1B[39;49;00m
        auto_decompress = True
        max_field_size = 8190
        max_headers = 128
        max_line_size = 8190
        read_bufsize = 262144
        read_until_eof = True
        real_timeout = ClientTimeout(total=300, connect=None, sock_read=None, sock_connect=30, ceil_threshold=5)
        req        = <aiohttp.client_reqrep.ClientRequest object at 0x000001673FA59C30>
        self       = <aiohttp.client.ClientSession object at 0x00000167407203A0>
        timer      = <aiohttp.helpers.TimerContext object at 0x00000167400C3FB0>
        traces     = []
#x1B[1m#x1B[31maiohttp\connector.py#x1B[0m:611: in connect
    #x1B[0mproto = #x1B[94mawait#x1B[39;49;00m #x1B[96mself#x1B[39;49;00m._create_connection(req, traces, timeout)#x1B[90m#x1B[39;49;00m
        conn       = None
        key        = ConnectionKey(host='localhost', port=56070, is_ssl=False, ssl=True, proxy=None, proxy_auth=None, proxy_headers_hash=None)
        placeholder = <aiohttp.connector._TransportPlaceholder object at 0x000001673FA5BBB0>
        req        = <aiohttp.client_reqrep.ClientRequest object at 0x000001673FA59C30>
        self       = <aiohttp.connector.TCPConnector object at 0x000001673FA58B80>
        timeout    = ClientTimeout(total=300, connect=None, sock_read=None, sock_connect=30, ceil_threshold=5)
        traces     = []
#x1B[1m#x1B[31maiohttp\connector.py#x1B[0m:1185: in _create_connection
    #x1B[0m_, proto = #x1B[94mawait#x1B[39;49;00m #x1B[96mself#x1B[39;49;00m._create_direct_connection(req, traces, timeout)#x1B[90m#x1B[39;49;00m
        req        = <aiohttp.client_reqrep.ClientRequest object at 0x000001673FA59C30>
        self       = <aiohttp.connector.TCPConnector object at 0x000001673FA58B80>
        timeout    = ClientTimeout(total=300, connect=None, sock_read=None, sock_connect=30, ceil_threshold=5)
        traces     = []
#x1B[1m#x1B[31maiohttp\connector.py#x1B[0m:1497: in _create_direct_connection
    #x1B[0m#x1B[94mraise#x1B[39;49;00m last_exc#x1B[90m#x1B[39;49;00m
        addr_infos = []
        client_error = <class 'aiohttp.client_exceptions.ClientConnectorError'>
        fingerprint = None
        host       = 'localhost'
        hosts      = [{'family': <AddressFamily.AF_INET6: 23>, 'flags': <AddressInfo.AI_NUMERICSERV|AI_NUMERICHOST: 12>, 'host': '::1', 'ho...INET: 2>, 'flags': <AddressInfo.AI_NUMERICSERV|AI_NUMERICHOST: 12>, 'host': '127.0.0.1', 'hostname': 'localhost', ...}]
        last_exc   = ClientConnectorError(ConnectionKey(host='localhost', port=56070, is_ssl=False, ssl=True, proxy=None, proxy_auth=None, ...headers_hash=None), ConnectionRefusedError(22, 'The remote computer refused the network connection', None, 1225, None))
        port       = 56070
        req        = <aiohttp.client_reqrep.ClientRequest object at 0x000001673FA59C30>
        self       = <aiohttp.connector.TCPConnector object at 0x000001673FA58B80>
        server_hostname = None
        sslcontext = None
        timeout    = ClientTimeout(total=300, connect=None, sock_read=None, sock_connect=30, ceil_threshold=5)
        traces     = []
#x1B[1m#x1B[31maiohttp\connector.py#x1B[0m:1467: in _create_direct_connection
    #x1B[0mtransp, proto = #x1B[94mawait#x1B[39;49;00m #x1B[96mself#x1B[39;49;00m._wrap_create_connection(#x1B[90m#x1B[39;49;00m
        addr_infos = []
        client_error = <class 'aiohttp.client_exceptions.ClientConnectorError'>
        fingerprint = None
        host       = 'localhost'
        hosts      = [{'family': <AddressFamily.AF_INET6: 23>, 'flags': <AddressInfo.AI_NUMERICSERV|AI_NUMERICHOST: 12>, 'host': '::1', 'ho...INET: 2>, 'flags': <AddressInfo.AI_NUMERICSERV|AI_NUMERICHOST: 12>, 'host': '127.0.0.1', 'hostname': 'localhost', ...}]
        last_exc   = ClientConnectorError(ConnectionKey(host='localhost', port=56070, is_ssl=False, ssl=True, proxy=None, proxy_auth=None, ...headers_hash=None), ConnectionRefusedError(22, 'The remote computer refused the network connection', None, 1225, None))
        port       = 56070
        req        = <aiohttp.client_reqrep.ClientRequest object at 0x000001673FA59C30>
        self       = <aiohttp.connector.TCPConnector object at 0x000001673FA58B80>
        server_hostname = None
        sslcontext = None
        timeout    = ClientTimeout(total=300, connect=None, sock_read=None, sock_connect=30, ceil_threshold=5)
        traces     = []
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <aiohttp.connector.TCPConnector object at 0x000001673FA58B80>
addr_infos = []
req = <aiohttp.client_reqrep.ClientRequest object at 0x000001673FA59C30>
timeout = ClientTimeout(total=300, connect=None, sock_read=None, sock_connect=30, ceil_threshold=5)
client_error = <class 'aiohttp.client_exceptions.ClientConnectorError'>
args = (functools.partial(<class 'aiohttp.client_proto.ResponseHandler'>, loop=<ProactorEventLoop running=False closed=False debug=False>),)
kwargs = {'server_hostname': None, 'ssl': None}

    #x1B[0m#x1B[94masync#x1B[39;49;00m #x1B[94mdef#x1B[39;49;00m#x1B[90m #x1B[39;49;00m#x1B[92m_wrap_create_connection#x1B[39;49;00m(#x1B[90m#x1B[39;49;00m
        #x1B[96mself#x1B[39;49;00m,#x1B[90m#x1B[39;49;00m
        *args: Any,#x1B[90m#x1B[39;49;00m
        addr_infos: #x1B[96mlist#x1B[39;49;00m[AddrInfoType],#x1B[90m#x1B[39;49;00m
        req: ClientRequestBase,#x1B[90m#x1B[39;49;00m
        timeout: #x1B[33m"#x1B[39;49;00m#x1B[33mClientTimeout#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m,#x1B[90m#x1B[39;49;00m
        client_error: #x1B[96mtype#x1B[39;49;00m[#x1B[96mException#x1B[39;49;00m] = ClientConnectorError,#x1B[90m#x1B[39;49;00m
        **kwargs: Any,#x1B[90m#x1B[39;49;00m
    ) -> #x1B[96mtuple#x1B[39;49;00m[asyncio.Transport, ResponseHandler]:#x1B[90m#x1B[39;49;00m
        #x1B[94mtry#x1B[39;49;00m:#x1B[90m#x1B[39;49;00m
            #x1B[94masync#x1B[39;49;00m #x1B[94mwith#x1B[39;49;00m ceil_timeout(#x1B[90m#x1B[39;49;00m
                timeout.sock_connect, ceil_threshold=timeout.ceil_threshold#x1B[90m#x1B[39;49;00m
            ):#x1B[90m#x1B[39;49;00m
                sock = #x1B[94mawait#x1B[39;49;00m aiohappyeyeballs.start_connection(#x1B[90m#x1B[39;49;00m
                    addr_infos=addr_infos,#x1B[90m#x1B[39;49;00m
                    local_addr_infos=#x1B[96mself#x1B[39;49;00m._local_addr_infos,#x1B[90m#x1B[39;49;00m
                    happy_eyeballs_delay=#x1B[96mself#x1B[39;49;00m._happy_eyeballs_delay,#x1B[90m#x1B[39;49;00m
                    interleave=#x1B[96mself#x1B[39;49;00m._interleave,#x1B[90m#x1B[39;49;00m
                    loop=#x1B[96mself#x1B[39;49;00m._loop,#x1B[90m#x1B[39;49;00m
                    socket_factory=#x1B[96mself#x1B[39;49;00m._socket_factory,#x1B[90m#x1B[39;49;00m
                )#x1B[90m#x1B[39;49;00m
                #x1B[90m# Add ssl_shutdown_timeout for Python 3.11+ when SSL is used#x1B[39;49;00m#x1B[90m#x1B[39;49;00m
                #x1B[94mif#x1B[39;49;00m (#x1B[90m#x1B[39;49;00m
                    kwargs.get(#x1B[33m"#x1B[39;49;00m#x1B[33mssl#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m)#x1B[90m#x1B[39;49;00m
                    #x1B[95mand#x1B[39;49;00m #x1B[96mself#x1B[39;49;00m._ssl_shutdown_timeout#x1B[90m#x1B[39;49;00m
                    #x1B[95mand#x1B[39;49;00m sys.version_info >= (#x1B[94m3#x1B[39;49;00m, #x1B[94m11#x1B[39;49;00m)#x1B[90m#x1B[39;49;00m
                ):#x1B[90m#x1B[39;49;00m
                    kwargs[#x1B[33m"#x1B[39;49;00m#x1B[33mssl_shutdown_timeout#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m] = #x1B[96mself#x1B[39;49;00m._ssl_shutdown_timeout#x1B[90m#x1B[39;49;00m
                #x1B[94mreturn#x1B[39;49;00m #x1B[94mawait#x1B[39;49;00m #x1B[96mself#x1B[39;49;00m._loop.create_connection(*args, **kwargs, sock=sock)#x1B[90m#x1B[39;49;00m
        #x1B[94mexcept#x1B[39;49;00m cert_errors #x1B[94mas#x1B[39;49;00m exc:#x1B[90m#x1B[39;49;00m
            #x1B[94mraise#x1B[39;49;00m ClientConnectorCertificateError(req.connection_key, exc) #x1B[94mfrom#x1B[39;49;00m#x1B[90m #x1B[39;49;00m#x1B[04m#x1B[96mexc#x1B[39;49;00m#x1B[90m#x1B[39;49;00m
        #x1B[94mexcept#x1B[39;49;00m ssl_errors #x1B[94mas#x1B[39;49;00m exc:#x1B[90m#x1B[39;49;00m
            #x1B[94mraise#x1B[39;49;00m ClientConnectorSSLError(req.connection_key, exc) #x1B[94mfrom#x1B[39;49;00m#x1B[90m #x1B[39;49;00m#x1B[04m#x1B[96mexc#x1B[39;49;00m#x1B[90m#x1B[39;49;00m
        #x1B[94mexcept#x1B[39;49;00m #x1B[96mOSError#x1B[39;49;00m #x1B[94mas#x1B[39;49;00m exc:#x1B[90m#x1B[39;49;00m
            #x1B[94mif#x1B[39;49;00m exc.errno #x1B[95mis#x1B[39;49;00m #x1B[94mNone#x1B[39;49;00m #x1B[95mand#x1B[39;49;00m #x1B[96misinstance#x1B[39;49;00m(exc, asyncio.TimeoutError):#x1B[90m#x1B[39;49;00m
                #x1B[94mraise#x1B[39;49;00m#x1B[90m#x1B[39;49;00m
>           #x1B[94mraise#x1B[39;49;00m client_error(req.connection_key, exc) #x1B[94mfrom#x1B[39;49;00m#x1B[90m #x1B[39;49;00m#x1B[04m#x1B[96mexc#x1B[39;49;00m#x1B[90m#x1B[39;49;00m
#x1B[1m#x1B[31mE           aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host localhost:56070 ssl:default [The remote computer refused the network connection]#x1B[0m

addr_infos = []
args       = (functools.partial(<class 'aiohttp.client_proto.ResponseHandler'>, loop=<ProactorEventLoop running=False closed=False debug=False>),)
client_error = <class 'aiohttp.client_exceptions.ClientConnectorError'>
kwargs     = {'server_hostname': None, 'ssl': None}
req        = <aiohttp.client_reqrep.ClientRequest object at 0x000001673FA59C30>
self       = <aiohttp.connector.TCPConnector object at 0x000001673FA58B80>
timeout    = ClientTimeout(total=300, connect=None, sock_read=None, sock_connect=30, ceil_threshold=5)

#x1B[1m#x1B[31maiohttp\connector.py#x1B[0m:1267: ClientConnectorError

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 23, 2026

Merging this PR will not alter performance

✅ 67 untouched benchmarks
⏩ 4 skipped benchmarks1


Comparing Bojun-Vvibe:fix/aio-libs-aiohttp-11293 (b78ee42) with master (365f717)

Open in CodSpeed

Footnotes

  1. 4 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided There is a change note present in this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test_aiohttp_request_ctx_manager_not_found fails intermittently

1 participant