Open Moosapoor opened 1 week ago
This code comes from stdlib. Is it possible that creating a socket can raise something other than OSError?
Is it possible that creating a socket can raise something other than OSError?
It happened in one of my projects and if I'm not wrong it was a RuntimeError
.
Can you post steps to recreate the issue without manually patching the exception, and post the exception trace you received in production?
I don't know how to reproduce the issue in the real world tbh. It happened couple of times and I couldn't find any specific situation which could result the issue. This is the stack trace:
WouldBlock: null
File "anyio/streams/memory.py", line 98, in receive
return self.receive_nowait()
File "anyio/streams/memory.py", line 93, in receive_nowait
raise WouldBlock
EndOfStream: null
File "starlette/middleware/base.py", line 159, in call_next
message = await recv_stream.receive()
File "anyio/streams/memory.py", line 118, in receive
raise EndOfStream
IndexError: list index out of range
...
File "starlette/middleware/base.py", line 165, in call_next
raise app_exc
File "starlette/middleware/base.py", line 151, in coro
await self.app(scope, receive_or_disconnect, send_no_error)
File "starlette/middleware/exceptions.py", line 65, in __call__
await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
File "starlette/_exception_handler.py", line 64, in wrapped_app
raise exc
File "starlette/_exception_handler.py", line 53, in wrapped_app
await app(scope, receive, sender)
File "starlette/routing.py", line 756, in __call__
await self.middleware_stack(scope, receive, send)
File "starlette/routing.py", line 776, in app
await route.handle(scope, receive, send)
File "starlette/routing.py", line 297, in handle
await self.app(scope, receive, send)
File "starlette/routing.py", line 77, in app
await wrap_app_handling_exceptions(app, request)(scope, receive, send)
File "starlette/_exception_handler.py", line 64, in wrapped_app
raise exc
File "starlette/_exception_handler.py", line 53, in wrapped_app
await app(scope, receive, sender)
File "starlette/routing.py", line 72, in app
response = await func(request)
File "fastapi/routing.py", line 297, in app
raw_response = await run_endpoint_function(
File "fastapi/routing.py", line 210, in run_endpoint_function
return await dependant.call(**values)
...
File "contextlib.py", line 210, in __aenter__
return await anext(self.gen)
...
File "contextlib.py", line 210, in __aenter__
return await anext(self.gen)
...
File "tenacity/_asyncio.py", line 71, in __anext__
do = self.iter(retry_state=self._retry_state)
File "__init__.py", line 314, in iter
return fut.result()
File "concurrent/futures/_base.py", line 449, in result
return self.__get_result()
File "concurrent/futures/_base.py", line 401, in __get_result
raise self._exception
...
File "contextlib.py", line 650, in enter_async_context
result = await _enter(cm)
File "contextlib.py", line 210, in __aenter__
return await anext(self.gen)
...
File "aiohttp/client.py", line 1353, in __aenter__
self._resp = await self._coro
File "aiohttp/client.py", line 657, in _request
conn = await self._connector.connect(
File "aiohttp/connector.py", line 564, in connect
proto = await self._create_connection(req, traces, timeout)
File "aiohttp/connector.py", line 975, in _create_connection
_, proto = await self._create_direct_connection(req, traces, timeout)
File "aiohttp/connector.py", line 1319, in _create_direct_connection
transp, proto = await self._wrap_create_connection(
File "aiohttp/connector.py", line 1073, in _wrap_create_connection
sock = await aiohappyeyeballs.start_connection(
File "aiohappyeyeballs/impl.py", line 102, in start_connection
first_exception = all_exceptions[0]
That traceback seems weirdly formatted, but I'm assuming the original exception comes from anyio, so maybe this is really a bug in anyio which should be raising some kind of OSError...?
To give some more context, the exceptions for _
here are:
[
RuntimeError('File descriptor 27 is used by transport <TCPTransport closed=False reading=True 0x2a4ce36edd00>'),
RuntimeError('File descriptor 27 is used by transport <TCPTransport closed=False reading=True 0x2a4ce36edd00>')
]
Describe the bug If creating the socket fails with an
Exception
other than anOSError
, thestart_connection
method will raise anIndexError
when it's trying to get the first exception.To Reproduce
Logs
Python version
aiohttp version
OS macOs
Additional context No additional context.