-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Possible bug in response.py when using Sanic + ASGI (chunked stream) #1964
Comments
@ashleysommer Thanks for looking into 🙏 . Yes it looks similar to #1730, I think it is worth to fix it since the chunked feature is very useful, I personally use it for video pseduo streaming. Thanks again! |
Looks like the way we're doing chunked-encoding is completely incompatible with the ASGI-spec here: Thats why our current solution works if httpx is the asgi-response-transport, but not if uvicorn or daphne are the transport. @huge-success/sanic-core-devs See the section in the spec regarding
So in asgi-mode we need to not set the |
@ashleysommer I agree, it should be ASGI's responsibility to "prepare" the chunking (when from Sanic we just set the flag). At the beginning I thought it was uvicorn' issue but then I realized that other gateways were doing the same so...I decided to open the issue. |
If anything, the bug is in the |
I've got a fix made, just need to package it up into a nice PR for master, and for the 20.9.x series, and also for the 19.12.x LTS series |
Fantastic! thank you so much, @ashleysommer! |
@logtheta (jtheta on the forum) was using v20.9.1 and would probably appreciate a v20.9.2 with this fix for their app, but I agree with you, we're only about a month away from the 20.12 release, and v19.12.4 or #master can be used with this fix until then. |
@ashleysommer @ahopkins, very much appreciated, v19.12.4 works as expected. |
Describe the bug
In response.py write method, if chunked==true the code will push the data into the stream specifying the len:
It looks like that uvicorn and daphne already execute this in httptools._impl.py (uvicorn>protocol>http) resulting in changing what the client will consider the body of the response.
If sanic is not using ASGI obviously we need that operation but if we use ASGI the content is prepared by the corresponding gateway.
How to reproduce
It is enough to stream a generic file and observe the response received by the client. With text files (like in the example) it's not big issue, but if you deal with media files, the decoder on client-side will just fail (I figured this out trying to stream mp4).
main.py
test.txt
Note: setting chunked=True in the response.file_stream() will make the response working but it is not the default value.
Environment:
Thanks!
The text was updated successfully, but these errors were encountered: