Closed SerodioJ closed 2 months ago
The issue is with uvloop
itself, not with uvicorn
. I don't know why, but it looks like uvloop
is not switching tasks properly... If you do await anyio.sleep(0)
it will force the event loop to switch tasks, and then you can have the behavior you want.
Please open an issue with a MRE on uvloop
. This MRE was too big for uvicorn itself.
@graingert do you know something about this?
I'll look into it
I've repeated this with plain websockets (mre incoming) will look at repeating with streams
Thanks Thomas. 🙏❤️
Initial Checks
Discussion Link
I am opening the issue because another user commented on the opened discussion thread, and no maintainer interacted with the thread.
Description
When running a FastAPI app with uvicorn default settings (--loop auto, which uses uvloop when installed), I started to notice that sometimes when handling multiple requests for the same path the response took longer than expected to arrive at the client. This issue became more noticeable when I tried using WebSockets to improve performance by returning the result in parts over the same connection instead of making multiple HTTP requests.
See discussion for more details.
Is this behavior expected when using the default event loop?
Example Code
FastAPI App Code
HTTP Client Code
WebSocket Client Code
Python, Uvicorn & OS Version