Skip to content
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

Ignore writing headers when in ASGI mode #1957

Merged
merged 9 commits into from Oct 25, 2020
Merged

Conversation

ahopkins
Copy link
Member

@ahopkins ahopkins commented Oct 25, 2020

This bug is fixed in #1876. In the interim, this resolves the issue and should be applied to both 19.12 and 20.9.

This resolves #1730 and also resolves #1653.

This branch can be tagged and pushed as v20.9.1. For 19.12, I will submit a seperate PR to the LTS branch.

Tronic
Tronic previously approved these changes Oct 25, 2020
Copy link
Member

@Tronic Tronic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A very cursory review: looks good. Note: this does not solve the double response header problem in some cases where exceptions are thrown after a response has already started, for which there is a separate issue open.

@ahopkins
Copy link
Member Author

for which there is a separate issue open.

@Tronic Which issue is that? Trying to replicate the issue.

@ahopkins ahopkins requested a review from Tronic October 25, 2020 09:15
@ahopkins
Copy link
Member Author

After approvals and passing tests, I will tag and push. After that I will "update branch", which will invalidate the approvals, so they will need to be submitted again.

@ashleysommer
Copy link
Member

ashleysommer commented Oct 25, 2020

Just curious, why did Multidict need to be updated in order to pass tests? I thought our pinned version of multidict worked fine? I saw the same change in #1956.

@ahopkins
Copy link
Member Author

It has to do with the new change to PIP that will not let you install conflicting versions of packages. Something else was using a higher pinned version so PIP now fails.

@ahopkins
Copy link
Member Author

Luckily upgrading to v5 had no impacts and tests all ran fine.

@ahopkins
Copy link
Member Author

FYI - the appveyor tests will start passing again once I pull master back in here before merge to master.

@ashleysommer
Copy link
Member

ashleysommer commented Oct 25, 2020

Go ahead and merge master, double check tests, then merge and release 20.9.1
Looks like the only other change since 20.9.0 is #1954 that is fine to include in the 20.9.1 release.

@ahopkins
Copy link
Member Author

OK.... pulling master in.

@codecov
Copy link

codecov bot commented Oct 25, 2020

Codecov Report

Merging #1957 into master will increase coverage by 0.19%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1957      +/-   ##
==========================================
+ Coverage   92.27%   92.47%   +0.19%     
==========================================
  Files          29       29              
  Lines        3236     3242       +6     
  Branches      570      571       +1     
==========================================
+ Hits         2986     2998      +12     
+ Misses        171      167       -4     
+ Partials       79       77       -2     
Impacted Files Coverage Δ
sanic/__version__.py 100.00% <100.00%> (ø)
sanic/asgi.py 96.25% <100.00%> (+3.24%) ⬆️
sanic/response.py 98.14% <100.00%> (+0.05%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9e048bc...9891828. Read the comment docs.

@ahopkins ahopkins merged commit e5aed4c into master Oct 25, 2020
@ahopkins ahopkins deleted the resolve-streaming-headers branch October 25, 2020 13:01
@Tronic
Copy link
Member

Tronic commented Oct 26, 2020

for which there is a separate issue open.

@Tronic Which issue is that? Trying to replicate the issue.

This is something that I came across during the streaming development, and frankly I cannot quite remember for sure if there was a bug in mainline or only in an earlier version of the streaming branch. Since I cannot find such issue now (open or closed), I'm inclined to think it was the latter.

@ahopkins
Copy link
Member Author

👍 I tried testing it pretty hard, and with the two additional tests, I think the coverage is pretty decent there. Soon enough we will be able to merge streaming.

@pytest.mark.asyncio
async def test_chunked_streaming_returns_correct_content_asgi(streaming_app):
request, response = await streaming_app.asgi_client.get("/")
assert response.text == "4\r\nfoo,\r\n3\r\nbar\r\n0\r\n\r\n"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So turns out this is wrong.
The response.text should be "foo,bar" just like in "test_chunked_streaming_returns_correct_content" non-asgi test.
The bug #1964 is causing the extra lengths and \r\n to be added by Sanic and by the ASGI handler.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, in the test this is correct because the the httpx asgi-response transport does not add in the chunking markers, so we need this in out response.text to verify that chunked mode was used correctly by the sanic-side stream fn.

But its still broken if using a real ASGI transport like Uvicorn of Daphne, because they do put in the chunking markers.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Continuing conversation in #1964

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ASGI Streaming response contains extra content In ASGI, headers is output as body
3 participants