Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix async cluster/cluster_info failure #63

Open
pquentin opened this issue Jun 21, 2024 · 1 comment
Open

Fix async cluster/cluster_info failure #63

pquentin opened this issue Jun 21, 2024 · 1 comment

Comments

@pquentin
Copy link
Member

Not unlike #62, cluster/cluster_info[0] with async mode:

2024-06-20 22:08:26 RT	_________________ test_rest_api_spec[cluster/cluster_info[0]] __________________
2024-06-20 22:08:26 RT	
2024-06-20 22:08:26 RT	self = <AiohttpHttpNode(https://[...]:443)>
2024-06-20 22:08:26 RT	method = 'GET', target = '/_info/ingest', body = None
2024-06-20 22:08:26 RT	headers = {'authorization': 'ApiKey <hidden>', 'accept': 'application/json', 'x-elastic-client-meta': 'esv=0.2.0.20231031,py=3.9.19,t=8.13.1,ai=3.9.5'}
2024-06-20 22:08:26 RT	request_timeout = <DEFAULT>
2024-06-20 22:08:26 RT	
2024-06-20 22:08:26 RT	    async def perform_request(  # type: ignore[override]
2024-06-20 22:08:26 RT	        self,
2024-06-20 22:08:26 RT	        method: str,
2024-06-20 22:08:26 RT	        target: str,
2024-06-20 22:08:26 RT	        body: Optional[bytes] = None,
2024-06-20 22:08:26 RT	        headers: Optional[HttpHeaders] = None,
2024-06-20 22:08:26 RT	        request_timeout: Union[DefaultType, Optional[float]] = DEFAULT,
2024-06-20 22:08:26 RT	    ) -> NodeApiResponse:
2024-06-20 22:08:26 RT	        global _AIOHTTP_FIXED_HEAD_BUG
2024-06-20 22:08:26 RT	        if self.session is None:
2024-06-20 22:08:26 RT	            self._create_aiohttp_session()
2024-06-20 22:08:26 RT	        assert self.session is not None
2024-06-20 22:08:26 RT	
2024-06-20 22:08:26 RT	        url = self.base_url + target
2024-06-20 22:08:26 RT	
2024-06-20 22:08:26 RT	        is_head = False
2024-06-20 22:08:26 RT	        # There is a bug in aiohttp<3.7 that disables the re-use
2024-06-20 22:08:26 RT	        # of the connection in the pool when method=HEAD.
2024-06-20 22:08:26 RT	        # See: aio-libs/aiohttp#1769
2024-06-20 22:08:26 RT	        if method == "HEAD" and not _AIOHTTP_FIXED_HEAD_BUG:
2024-06-20 22:08:26 RT	            method = "GET"
2024-06-20 22:08:26 RT	            is_head = True
2024-06-20 22:08:26 RT	
2024-06-20 22:08:26 RT	        # total=0 means no timeout for aiohttp
2024-06-20 22:08:26 RT	        resolved_timeout: Optional[float] = (
2024-06-20 22:08:26 RT	            self.config.request_timeout
2024-06-20 22:08:26 RT	            if request_timeout is DEFAULT
2024-06-20 22:08:26 RT	            else request_timeout
2024-06-20 22:08:26 RT	        )
2024-06-20 22:08:26 RT	        aiohttp_timeout = aiohttp.ClientTimeout(
2024-06-20 22:08:26 RT	            total=resolved_timeout if resolved_timeout is not None else 0
2024-06-20 22:08:26 RT	        )
2024-06-20 22:08:26 RT	
2024-06-20 22:08:26 RT	        request_headers = self._headers.copy()
2024-06-20 22:08:26 RT	        if headers:
2024-06-20 22:08:26 RT	            request_headers.update(headers)
2024-06-20 22:08:26 RT	
2024-06-20 22:08:26 RT	        body_to_send: Optional[bytes]
2024-06-20 22:08:26 RT	        if body:
2024-06-20 22:08:26 RT	            if self._http_compress:
2024-06-20 22:08:26 RT	                body_to_send = gzip.compress(body)
2024-06-20 22:08:26 RT	                request_headers["content-encoding"] = "gzip"
2024-06-20 22:08:26 RT	            else:
2024-06-20 22:08:26 RT	                body_to_send = body
2024-06-20 22:08:26 RT	        else:
2024-06-20 22:08:26 RT	            body_to_send = None
2024-06-20 22:08:26 RT	
2024-06-20 22:08:26 RT	        kwargs = {}
2024-06-20 22:08:26 RT	        if self._ssl_assert_fingerprint:
2024-06-20 22:08:26 RT	            kwargs["ssl"] = aiohttp_fingerprint(self._ssl_assert_fingerprint)
2024-06-20 22:08:26 RT	
2024-06-20 22:08:26 RT	        try:
2024-06-20 22:08:26 RT	            start = self._loop.time()
2024-06-20 22:08:26 RT	            async with self.session.request(
2024-06-20 22:08:26 RT	                method,
2024-06-20 22:08:26 RT	                url,
2024-06-20 22:08:26 RT	                data=body_to_send,
2024-06-20 22:08:26 RT	                headers=request_headers,
2024-06-20 22:08:26 RT	                timeout=aiohttp_timeout,
2024-06-20 22:08:26 RT	                **kwargs,
2024-06-20 22:08:26 RT	            ) as response:
2024-06-20 22:08:26 RT	                if is_head:  # We actually called 'GET' so throw away the data.
2024-06-20 22:08:26 RT	                    await response.release()
2024-06-20 22:08:26 RT	                    raw_data = b""
2024-06-20 22:08:26 RT	                else:
2024-06-20 22:08:26 RT	>                   raw_data = await response.read()
2024-06-20 22:08:26 RT	
2024-06-20 22:08:26 RT	.nox/test-3-9/lib/python3.9/site-packages/elastic_transport/_node/_http_aiohttp.py:191:
2024-06-20 22:08:26 RT	_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
2024-06-20 22:08:26 RT	.nox/test-3-9/lib/python3.9/site-packages/aiohttp/client_reqrep.py:1111: in read
2024-06-20 22:08:26 RT	    self._body = await self.content.read()
2024-06-20 22:08:26 RT	.nox/test-3-9/lib/python3.9/site-packages/aiohttp/streams.py:383: in read
2024-06-20 22:08:26 RT	    block = await self.readany()
2024-06-20 22:08:26 RT	.nox/test-3-9/lib/python3.9/site-packages/aiohttp/streams.py:405: in readany
2024-06-20 22:08:26 RT	    await self._wait("readany")
2024-06-20 22:08:26 RT	.nox/test-3-9/lib/python3.9/site-packages/aiohttp/streams.py:312: in _wait
2024-06-20 22:08:26 RT	    await waiter
2024-06-20 22:08:26 RT	_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
2024-06-20 22:08:26 RT	
2024-06-20 22:08:26 RT	self = <aiohttp.helpers.TimerContext object at 0x7f9421094a90>
2024-06-20 22:08:26 RT	exc_type = <class 'asyncio.exceptions.CancelledError'>
2024-06-20 22:08:26 RT	exc_val = CancelledError(), exc_tb = <traceback object at 0x7f9420f9b9c0>
2024-06-20 22:08:26 RT	
2024-06-20 22:08:26 RT	    def __exit__(
2024-06-20 22:08:26 RT	        self,
2024-06-20 22:08:26 RT	        exc_type: Optional[Type[BaseException]],
2024-06-20 22:08:26 RT	        exc_val: Optional[BaseException],
2024-06-20 22:08:26 RT	        exc_tb: Optional[TracebackType],
2024-06-20 22:08:26 RT	    ) -> Optional[bool]:
2024-06-20 22:08:26 RT	        if self._tasks:
2024-06-20 22:08:26 RT	            self._tasks.pop()
2024-06-20 22:08:26 RT	
2024-06-20 22:08:26 RT	        if exc_type is asyncio.CancelledError and self._cancelled:
2024-06-20 22:08:26 RT	>           raise asyncio.TimeoutError from None
2024-06-20 22:08:26 RT	E           asyncio.exceptions.TimeoutError
2024-06-20 22:08:26 RT	
2024-06-20 22:08:26 RT	.nox/test-3-9/lib/python3.9/site-packages/aiohttp/helpers.py:735: TimeoutError
2024-06-20 22:08:26 RT	
2024-06-20 22:08:26 RT	The above exception was the direct cause of the following exception:
2024-06-20 22:08:26 RT	
2024-06-20 22:08:26 RT	test_spec = {}
2024-06-20 22:08:26 RT	async_runner = <test_elasticsearch_serverless.test_async.test_server.test_rest_api_spec.AsyncYamlRunner object at 0x7f94204c2940>
2024-06-20 22:08:26 RT	
2024-06-20 22:08:26 RT	    @pytest.mark.parametrize("test_spec", YAML_TEST_SPECS)
2024-06-20 22:08:26 RT	    async def test_rest_api_spec(test_spec, async_runner):
2024-06-20 22:08:26 RT	        if test_spec.get("fail", False):
2024-06-20 22:08:26 RT	            pytest.xfail("Manually marked as failing in 'FAILING_TESTS'")
2024-06-20 22:08:26 RT	        async_runner.use_spec(test_spec)
2024-06-20 22:08:26 RT	>       await async_runner.run()
2024-06-20 22:08:26 RT	
2024-06-20 22:08:26 RT	test_elasticsearch_serverless/test_async/test_server/test_rest_api_spec.py:255:
2024-06-20 22:08:26 RT	_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
2024-06-20 22:08:26 RT	test_elasticsearch_serverless/test_async/test_server/test_rest_api_spec.py:95: in run
2024-06-20 22:08:26 RT	    await self.run_code(self._run_code)
2024-06-20 22:08:26 RT	test_elasticsearch_serverless/test_async/test_server/test_rest_api_spec.py:110: in run_code
2024-06-20 22:08:26 RT	    await await_if_coro(getattr(self, "run_" + action_type)(action))
2024-06-20 22:08:26 RT	test_elasticsearch_serverless/test_async/test_server/test_rest_api_spec.py:50: in await_if_coro
2024-06-20 22:08:26 RT	    return await x
2024-06-20 22:08:26 RT	test_elasticsearch_serverless/test_async/test_server/test_rest_api_spec.py:180: in run_do
2024-06-20 22:08:26 RT	    self.last_response = (await api(**args)).body
2024-06-20 22:08:26 RT	elasticsearch_serverless/_async/client/cluster.py:223: in info
2024-06-20 22:08:26 RT	    return await self.perform_request(  # type: ignore[return-value]
2024-06-20 22:08:26 RT	elasticsearch_serverless/_async/client/_base.py:257: in perform_request
2024-06-20 22:08:26 RT	    return await self._client.perform_request(
2024-06-20 22:08:26 RT	elasticsearch_serverless/_async/client/_base.py:153: in perform_request
2024-06-20 22:08:26 RT	    meta, resp_body = await self.transport.perform_request(
2024-06-20 22:08:26 RT	.nox/test-3-9/lib/python3.9/site-packages/elastic_transport/_async_transport.py:264: in perform_request
2024-06-20 22:08:26 RT	    resp = await node.perform_request(
2024-06-20 22:08:26 RT	_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
2024-06-20 22:08:26 RT	
2024-06-20 22:08:26 RT	self = <AiohttpHttpNode(https://[...]:443)>
2024-06-20 22:08:26 RT	method = 'GET', target = '/_info/ingest', body = None
2024-06-20 22:08:26 RT	headers = {'authorization': 'ApiKey <hidden>', 'accept': 'application/json', 'x-elastic-client-meta': 'esv=0.2.0.20231031,py=3.9.19,t=8.13.1,ai=3.9.5'}
2024-06-20 22:08:26 RT	request_timeout = <DEFAULT>
2024-06-20 22:08:26 RT	
2024-06-20 22:08:26 RT	    async def perform_request(  # type: ignore[override]
2024-06-20 22:08:26 RT	        self,
2024-06-20 22:08:26 RT	        method: str,
2024-06-20 22:08:26 RT	        target: str,
2024-06-20 22:08:26 RT	        body: Optional[bytes] = None,
2024-06-20 22:08:26 RT	        headers: Optional[HttpHeaders] = None,
2024-06-20 22:08:26 RT	        request_timeout: Union[DefaultType, Optional[float]] = DEFAULT,
2024-06-20 22:08:26 RT	    ) -> NodeApiResponse:
2024-06-20 22:08:26 RT	        global _AIOHTTP_FIXED_HEAD_BUG
2024-06-20 22:08:26 RT	        if self.session is None:
2024-06-20 22:08:26 RT	            self._create_aiohttp_session()
2024-06-20 22:08:26 RT	        assert self.session is not None
2024-06-20 22:08:26 RT	
2024-06-20 22:08:26 RT	        url = self.base_url + target
2024-06-20 22:08:26 RT	
2024-06-20 22:08:26 RT	        is_head = False
2024-06-20 22:08:26 RT	        # There is a bug in aiohttp<3.7 that disables the re-use
2024-06-20 22:08:26 RT	        # of the connection in the pool when method=HEAD.
2024-06-20 22:08:26 RT	        # See: aio-libs/aiohttp#1769
2024-06-20 22:08:26 RT	        if method == "HEAD" and not _AIOHTTP_FIXED_HEAD_BUG:
2024-06-20 22:08:26 RT	            method = "GET"
2024-06-20 22:08:26 RT	            is_head = True
2024-06-20 22:08:26 RT	
2024-06-20 22:08:26 RT	        # total=0 means no timeout for aiohttp
2024-06-20 22:08:26 RT	        resolved_timeout: Optional[float] = (
2024-06-20 22:08:26 RT	            self.config.request_timeout
2024-06-20 22:08:26 RT	            if request_timeout is DEFAULT
2024-06-20 22:08:26 RT	            else request_timeout
2024-06-20 22:08:26 RT	        )
2024-06-20 22:08:26 RT	        aiohttp_timeout = aiohttp.ClientTimeout(
2024-06-20 22:08:26 RT	            total=resolved_timeout if resolved_timeout is not None else 0
2024-06-20 22:08:26 RT	        )
2024-06-20 22:08:26 RT	
2024-06-20 22:08:26 RT	        request_headers = self._headers.copy()
2024-06-20 22:08:26 RT	        if headers:
2024-06-20 22:08:26 RT	            request_headers.update(headers)
2024-06-20 22:08:26 RT	
2024-06-20 22:08:26 RT	        body_to_send: Optional[bytes]
2024-06-20 22:08:26 RT	        if body:
2024-06-20 22:08:26 RT	            if self._http_compress:
2024-06-20 22:08:26 RT	                body_to_send = gzip.compress(body)
2024-06-20 22:08:26 RT	                request_headers["content-encoding"] = "gzip"
2024-06-20 22:08:26 RT	            else:
2024-06-20 22:08:26 RT	                body_to_send = body
2024-06-20 22:08:26 RT	        else:
2024-06-20 22:08:26 RT	            body_to_send = None
2024-06-20 22:08:26 RT	
2024-06-20 22:08:26 RT	        kwargs = {}
2024-06-20 22:08:26 RT	        if self._ssl_assert_fingerprint:
2024-06-20 22:08:26 RT	            kwargs["ssl"] = aiohttp_fingerprint(self._ssl_assert_fingerprint)
2024-06-20 22:08:26 RT	
2024-06-20 22:08:26 RT	        try:
2024-06-20 22:08:26 RT	            start = self._loop.time()
2024-06-20 22:08:26 RT	            async with self.session.request(
2024-06-20 22:08:26 RT	                method,
2024-06-20 22:08:26 RT	                url,
2024-06-20 22:08:26 RT	                data=body_to_send,
2024-06-20 22:08:26 RT	                headers=request_headers,
2024-06-20 22:08:26 RT	                timeout=aiohttp_timeout,
2024-06-20 22:08:26 RT	                **kwargs,
2024-06-20 22:08:26 RT	            ) as response:
2024-06-20 22:08:26 RT	                if is_head:  # We actually called 'GET' so throw away the data.
2024-06-20 22:08:26 RT	                    await response.release()
2024-06-20 22:08:26 RT	                    raw_data = b""
2024-06-20 22:08:26 RT	                else:
2024-06-20 22:08:26 RT	                    raw_data = await response.read()
2024-06-20 22:08:26 RT	                duration = self._loop.time() - start
2024-06-20 22:08:26 RT	
2024-06-20 22:08:26 RT	        # We want to reraise a cancellation or recursion error.
2024-06-20 22:08:26 RT	        except RERAISE_EXCEPTIONS:
2024-06-20 22:08:26 RT	            raise
2024-06-20 22:08:26 RT	        except Exception as e:
2024-06-20 22:08:26 RT	            err: Exception
2024-06-20 22:08:26 RT	            if isinstance(
2024-06-20 22:08:26 RT	                e, (asyncio.TimeoutError, aiohttp_exceptions.ServerTimeoutError)
2024-06-20 22:08:26 RT	            ):
2024-06-20 22:08:26 RT	                err = ConnectionTimeout(
2024-06-20 22:08:26 RT	                    "Connection timed out during request", errors=(e,)
2024-06-20 22:08:26 RT	                )
2024-06-20 22:08:26 RT	            elif isinstance(e, (ssl.SSLError, aiohttp_exceptions.ClientSSLError)):
2024-06-20 22:08:26 RT	                err = TlsError(str(e), errors=(e,))
2024-06-20 22:08:26 RT	            elif isinstance(e, BUILTIN_EXCEPTIONS):
2024-06-20 22:08:26 RT	                raise
2024-06-20 22:08:26 RT	            else:
2024-06-20 22:08:26 RT	                err = ConnectionError(str(e), errors=(e,))
2024-06-20 22:08:26 RT	            self._log_request(
2024-06-20 22:08:26 RT	                method="HEAD" if is_head else method,
2024-06-20 22:08:26 RT	                target=target,
2024-06-20 22:08:26 RT	                headers=request_headers,
2024-06-20 22:08:26 RT	                body=body,
2024-06-20 22:08:26 RT	                exception=err,
2024-06-20 22:08:26 RT	            )
2024-06-20 22:08:26 RT	>           raise err from e
2024-06-20 22:08:26 RT	E           elastic_transport.ConnectionTimeout: Connection timed out
2024-06-20 22:08:26 RT	
2024-06-20 22:08:26 RT	.nox/test-3-9/lib/python3.9/site-packages/elastic_transport/_node/_http_aiohttp.py:218: ConnectionTimeout
@pquentin
Copy link
Member Author

Currently blocked on elastic/elastic-transport-python#197.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant