Skip to content

Support ASGI middleware chains by only yielding http.disconnect when response has been fully received #153

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

Merged
merged 10 commits into from
Dec 7, 2022

Conversation

tonybaloney
Copy link
Contributor

@tonybaloney tonybaloney commented Dec 2, 2022

Fixes a bug where http.disconnect would be sent even though the ASGI middleware hadn't received the whole response, which yielded empty responses.

This was shown with 2 or more pieces of FastAPI middleware because it would send them in chunks.

As per the ASGI spec, http.disconnect should be sent when:

Sent to the application if receive is called after a response has been sent or after the HTTP connection has been closed. This is mainly useful for long-polling, where you may want to trigger cleanup code if the connection closes early.

So the receive method has been changed to only send then when all response body has been added to the buffer.

Fixes Azure/azure-functions-python-worker#1104

@tonybaloney tonybaloney changed the title Middleware chaining Support ASGI middleware chains by only yielding http.disconnect when response has been fully received Dec 2, 2022
Copy link
Member

@YunchuWang YunchuWang left a comment

Choose a reason for hiding this comment

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

LGTM

@codecov
Copy link

codecov bot commented Dec 6, 2022

Codecov Report

Merging #153 (1f0926e) into dev (bd11d48) will decrease coverage by 0.05%.
The diff coverage is 71.42%.

@@            Coverage Diff             @@
##              dev     #153      +/-   ##
==========================================
- Coverage   90.13%   90.08%   -0.06%     
==========================================
  Files          50       50              
  Lines        3002     3005       +3     
  Branches      400      401       +1     
==========================================
+ Hits         2706     2707       +1     
- Misses        220      221       +1     
- Partials       76       77       +1     
Flag Coverage Δ
unittests 90.04% <71.42%> (-0.06%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
azure/functions/_http_asgi.py 90.42% <71.42%> (-1.89%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@YunchuWang YunchuWang merged commit 1ab44dd into Azure:dev Dec 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Azure Function AsgiMiddleware Not Responding
2 participants