Streaming response early disconnect mode#2687
Closed
dmitry-mli wants to merge 1 commit intoKludex:masterfrom
Closed
Streaming response early disconnect mode#2687dmitry-mli wants to merge 1 commit intoKludex:masterfrom
dmitry-mli wants to merge 1 commit intoKludex:masterfrom
Conversation
345b34b to
7d0bfbe
Compare
7d0bfbe to
5cd92cd
Compare
Author
|
@Kludex @adriangb please review, thank you! This fixes backward incompatible change made in #2620, details in the description. @dzhulgakov FYI |
Contributor
Contributor
|
Thank you for proposing a fix! Can we go with #2688 instead? It's a much smaller diff / code change. |
Author
|
Sure thing, approved (with comments)! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Starlette 0.38.4 introduced a bugfix that also introduced a backward incompatible change. This PR keep both the original fix as well as recovers the backward compatibility through parameterization.
#2620 solved issue
#2620 delivered an important fix for
BaseHTTPMiddlewarewhich relied onStreamingResponsefor chained upstream and downstream communication. Unfortunately,StreamingResponseoptimized for early disconnect which resulted into unexpected termination for some of middleware handlers, in case the communication did not manage to propagate through a longer stack (a stack of 4 was enough to reproduce).#2620 created issue
Change #2620 introduced a backward incompatible change for streaming response from
BaseHTTPMiddleware(background tasks were dropped). This impacted software that relied async post-processing.This PR content
This PR extends
StreamingResponsewithearly_disconnectflag (defaultTrue) that controls the early disconnect behavior that is undesirable for the middleware caseBaseHTTPMiddleware. The flag is backward compatible for clients ofStreamingResponse. The_StreamingResponseis reverted back to inherit fromStreamingResponsebut this time suppressing the early disconnect mode. Unit tests extended to cover the case.Checklist