Running FastAPI app and getting a Starlette error #1100
Replies: 5 comments 8 replies
-
Do you have a minimal reproducer? |
Beta Was this translation helpful? Give feedback.
-
Heh, assume I know nothing about FastAPI apps...
Thanks!
You shouldn't need to restart it generally... but there are times you do... |
Beta Was this translation helpful? Give feedback.
-
If I just have a "get" endpoint with no request nor response body, I get this error every time:
If I remove the middleware, the error disappears. To me, it seems like there is some problem with nginx unit and fastapi/starlette middleware. |
Beta Was this translation helpful? Give feedback.
-
Thanks, I'll have a look at your reproducer. What is the middleware you mention? |
Beta Was this translation helpful? Give feedback.
-
OK, I've reproduced this. This is perhaps better tracked in an issue. I'll transfer this over. |
Beta Was this translation helpful? Give feedback.
-
I am running a FastAPI app using nginx unit, and using a python script to send multiple sequential (wait for response before sending next) requests to it with the "requests" library. When I reuse the same
requests.Session
object for all the requests, so thatrequests.Session.close
is not called, then I get intermittent crashes in the application and thus status 500 back.The error is coming from this line: https://github.com/encode/starlette/blob/master/starlette/middleware/base.py#L56
which appears to be starlette waiting for a client disconnect but instead getting the next request. (No idea why starlette wants the request to be closed instead of allowing it to be reused for the next request, but maybe there is something I am not aware of.)
I would (and will) ask about this in the starlette github, but I am posting here because I did not encounter this issue when running my FastAPI app with uvicorn, it only happens with nginx unit, so at a minimum, it appears that something is different here which is causing problems, and this is probably something that should be identified.
I was really happy when I discovered nginx unit; this issue is currently the only thing that is preventing me from adopting it.
Beta Was this translation helpful? Give feedback.
All reactions