-
-
Notifications
You must be signed in to change notification settings - Fork 747
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
HttpToolsProtocol: receive() hangs due to signalling mixup between request cycles #748
Comments
hi @itayperl |
@euri10, I'm sorry if my description was a bit unclear, but this is a bug in uvicorn that should be fixed regardless of Starlette. It just didn't manifest (in my usecase at least) with older versions of Starlette. Any code working with multiple httptools_impl.RequestResponseCycle objects in parallel can potentially hit this bug. |
could you either confirm you experience this on 0.13.8 too (because can't remember exactly but I think 0.13.8 reverted something in middleware that makes me think it's related, can be totally off of course) |
I was able to reproduce the bug on both 0.13.6 and 0.13.8 by adding the 100ms sleep in starlette as described above. I can't say if it will actually reproduce "in the field" in either version, without the sleep, but I did see it happen on 0.13.7 in a real production setting after a day or so of operation. |
ok I don't want to ditch this one, but the fact you have to kind of "hack"
the app to reproduce doesn't help.
To stay constructive, what would be fantastic would be a simple asgi app
that reproduces the issue, then we can advise on what to do next, seems ok
for you ?
…On Mon, Oct 12, 2020 at 3:37 PM Itay Perl ***@***.***> wrote:
I was able to reproduce the bug on both 0.13.6 and 0.13.8 by adding the
100ms sleep in starlette as described above.
I can't say if it will actually reproduce "in the field" in either
version, without the sleep, but I did see it happen on 0.13.7 in a real
production setting after a day or so of operation.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#748 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAINSPT7ZLV7CV2R5CPKRKLSKMBCDANCNFSM4PZJ7CMQ>
.
--
benoit barthelet
http://pgp.mit.edu/pks/lookup?op=get&search=0xF150E01A72F6D2EE
|
Edit: updated test case moved to issue description |
@euri10, were you able to reproduce the bug using the new test case? |
I can yes, this helped a lot thanks |
I have a FastAPI server running with uvicorn. Starting with starlette 0.13.7 I'm hitting a race condition on a specific resource limited setup (RPi), however if my analysis is correct the root cause is a bug in uvicorn's protocol.http.httptools_impl.
The race condition is causing starlette to keep receive()ing on a RequestResponseCycle for a bit after the response is fully sent, while the client sends a new request on the same connection:
message_event
in RequestResponseCycle.receive() (called beforeresponse_complete
is set)message_event
message_event
and returnsmessage_event
is already clearedIf I'm not mistaken, the fix is pretty simple:
response_complete
also setmessage_event
to kill any lingering receive()sMinimal test case
This raw ASGI server imitates the behavior in Starlette that triggers the bug.
Test with
curl localhost:8000/foo localhost:8000/bar
. You should see that it hangs at the request to /bar.The /foo request calls receive() in the background, and this call is still running in the background when the request to /bar arrives. The
http.request
message for the /bar request incorrectly wakes up the background (/foo) receive, causing the receive() for /bar to hang forever, as there are no more events for this request.The text was updated successfully, but these errors were encountered: