-
-
Notifications
You must be signed in to change notification settings - Fork 948
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
HTTPMiddleware
breaks BackgroundTasks
in the same connection
#2093
Comments
Thanks for the report @Molkree 👍 |
I have experienced the same issue. It took me a wile to figure out this was the issue. Only after establishing that the move from Starlette 0.23.0 to 0.23.1 partially broke my FastApi application was I able to find these posts as an explanation of what was going on. I have been able to resolve it by ditching my @api.middleware('http') middelware and rewriting it as pure ASGI middleware instead, following the documentation here: https://www.starlette.io/middleware/#writing-pure-asgi-middleware. |
@Kludex Is it ok to PR regarding this issue for a review? |
You mean that you want to create a PR? Yeah, go ahead. |
Is anyone working on this issue? It's quite important for us and I think whether it is necessary to fix it myself or someone is already doing it? |
@nikita-b No one is working on this issue. Go ahead. 🙏 |
I need this for the next release. |
I'm not sure if we can fix this without breaking what was previously fixed. |
I’m going to check what the behavior is like under #1700, maybe that’s a viable fix |
I can confirm that #1700 fixes this. I'll re-open it. |
I think we should try to find the cause first, and try to find a solution that just fixes the issue. |
Consider the following simple example of background tasks through Starlette:
server.py
I start this code with
uvicorn server:app --reload
.Then I start the task twice in one connection using this code:
client.py
Which results in a sequential execution of background tasks (and read timeout from the client as a consequence):
If I just send simple curl requests (
curl -X 'POST' 'http://127.0.0.1:8000/task'
) one after the other (so they are different connections), everything works as expected:It looks like this regression was introduced in Starlette 0.23.1, this PR. If I pin Starlette to 0.23.0 everything works fine.
The text was updated successfully, but these errors were encountered: