-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Open
Labels
Description
Checklist
- The bug is reproducible against the latest release and/or
master. - There are no similar issues or pull requests to fix it yet.
Describe the bug
The requests.request interface exposes an stream=True option which results on the call not waiting for the entire body to arrive.
stream=True is not handled properly by starlette.testclient._ASGIAdapter.send, as it is unconditionally waiting for the entire request to finish:
To reproduce
- Perform an event wait
asyncio.Eventwait()after your ASGI application responds with your headers (http.response.start) and first chunk (http.response.body), this can be easily done inside the generator passed tostarlette.StreamingResponse. - Set the event via
asyncio.Eventset()only after doing the request withstream=True. - Deadlock.
Expected behavior
With stream=True, TestClient.request should return right after first http.response.body (asgiref defines server must sent http.response.start headers only after the first http.response.body event is generated).
Streaming-related response methods (like iter_content) should be implemented via awaiting further http.response.body until more_body is missing or False.
Actual behavior
Deadlock.
Additional context
I suspect #533 could be related to this.
falkben, jamesbraza, willarmiros, matt3o and marigoold