Closed Kludex closed 6 months ago
So, I did a little digging into Starlette and the problematic line of code is Here. Maybe an issue should be opened there as well?
The problem stems from sending responses to an already disconnected request. Previously, Uvicorn just had a pass
if the request is disconnected, but now it raises a ClientDisconnected
error which isn't handled in Starlette for that case.
While this should be fixed (or handled appropriately) in Starlette, FastAPI doesn't support starlette > v0.36.x.
For a workaround, I'm using sse-starlette which doesn't have this issue and won't bring dependency conflicts with FastAPI.
The main takeaway is to not yield after a request is disconnected (or check if it's disconnected before yielding). Hopefully this helps someone with the same problem!
Since a lot of people are watching this, can someone create a PR reverting the PR that caused this?
We need a backwards-compatible strategy here before adding this feature again.
Estou com o mesmo problema !
Então, investiguei um pouco o Starlette e a linha de código problemática está Here . Talvez um problema deva ser aberto lá também?
O problema decorre do envio de respostas a uma solicitação já desconectada. Anteriormente, o Uvicorn só tinha uma
pass
solicitação se a solicitação fosse desconectada, mas agora gera umClientDisconnected
erro que não é tratado no Starlette para esse caso.Embora isso deva ser corrigido (ou tratado adequadamente) no Starlette, FastAPI não oferece suporte a starlette > v0.36.x.
Para uma solução alternativa, estou usando o sse-starlette que não apresenta esse problema e não trará conflitos de dependência com FastAPI.
A principal lição é não ceder depois que uma solicitação for desconectada (ou verificar se ela está desconectada antes de ceder). Espero que isso ajude alguém com o mesmo problema!
Tem alguma previsão de suporte a isso @tiangolo ?
Um caminho que encontrei foi voltar para o uvicorn[standard]==0.27.0
que é anterior a PR que adiciona o comportamento indesejado
Wanted to fill in that I'm seeing this when using the wsgimiddleware provided by fastapi while using unicorn 0.28.0
The fix will be released on 0.28.1 in a couple of hours.
Discussed in https://github.com/encode/uvicorn/discussions/2270