-
-
Notifications
You must be signed in to change notification settings - Fork 920
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
Don't poll for disconnects in BaseHTTPMiddleware via StreamingResponse #2620
Conversation
I can confirm that this PR fixes the example I have reproduced in #2516 (comment) |
Maybe we should consider to add a section to: https://www.starlette.io/middleware/#basehttpmiddleware emphasising this. |
Seems like the issue now is coverage in tests (all of the tests still pass). There are several pieces of test code that are not not being hit but I'm not sure if they were essential or just an implementation detail, some more careful evaluation is needed. |
@adriangb, what is the status of this PR? |
Hi @adriangb , thanks for this fix. |
This PR needs someone motivated to check why the coverage dropped. Anyone that uses BaseHTTPMiddleware in their company, and wants to spend some engineers hours working on this, is welcome. Otherwise, you can try to sponsor @adriangb as an appreciation gesture for his efforts here, and maybe motivate him to continue the work here. |
Co-authored-by: Mikkel Duif <[email protected]>
3104f2c
to
0679356
Compare
@Kludex I looked into the coverage. Basically before we were using For example, if I check out master and apply the changes to
|
@Kludex Could you please review this PR when you get a chance? I appreciate your time! |
I'm a bit tired of people asking me stuff. I'm very dedicated to the projects I maintain, which means people just need to wait a bit. I don't like people pressuring me to review stuff. You want to motivate me to check this PR? Feel free to sponsor me. Otherwise, wait for me to voluntarily come here and review it. Too many issues regarding BaseHTTPMiddleware, and I need to check previous work and make sure this is fine. It takes time. |
Fix and enable again starlette tests that were disabled. Reason of the bug: - starlette was fixed in 0.38.3 for an issue that was causing trouble in our appsec instrumentation. Tests were upgraded accordingly Fix: encode/starlette#2620 Issue: encode/starlette#2516 Also improve the guards in the asgi middleware appsec instrumentation for request body to ensure that we never break. ## Checklist - [x] PR author has checked that all the criteria below are met - The PR description includes an overview of the change - The PR description articulates the motivation for the change - The change includes tests OR the PR description describes a testing strategy - The PR description notes risks associated with the change, if any - Newly-added code is easy to change - The change follows the [library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) - The change includes or references documentation updates if necessary - Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) ## Reviewer Checklist - [x] Reviewer has checked that all the criteria below are met - Title is accurate - All changes are related to the pull request's stated goal - Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes - Testing strategy adequately addresses listed risks - Newly-added code is easy to change - Release note makes sense to a user of the library - If necessary, author has acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment - Backport labels are set in a manner that is consistent with the [release branch maintenance policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)
status_code: int = 200, | ||
headers: typing.Mapping[str, str] | None = None, | ||
media_type: str | None = None, | ||
background: BackgroundTask | None = None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is the removal of background
here intentional? We use background
for both actual background tasks but also to detect when a streaming request was cancelled by the client (request.is_disconnected
had some minor overhead).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cutting a PR for this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
encode#2620) * Don't poll for disconnects in BaseHTTPMiddleware via StreamingResponse Fixes encode#2516 * add test * fmt * Update tests/middleware/test_base.py Co-authored-by: Mikkel Duif <[email protected]> * add test for line now missing coverage * more coverage, fix test * add comment * fmt * tweak test * fix * fix coverage * relint --------- Co-authored-by: Mikkel Duif <[email protected]>
Fixes #2516