-
-
Notifications
You must be signed in to change notification settings - Fork 978
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
Remove maxsize arg from Queue constructor in BaseHTTPMiddleware #1028
Conversation
An alternative to this PR is to leave the fix in the codebase and instead to change the docs to explicitly state that any Something like:
class CustomHeaderMiddleware(BaseHTTPMiddleware):
async def dispatch(self, request, call_next):
response = await call_next(request)
if response.headers['Custom'] == 'Example':
# NEVER DO THIS:
return SomeOtherResponse
return response
Indeed, one argument for changing the docs instead is that users can control whether or not they throw away the unevaluated response. By contrast, they don't have any control over the queue size in this Thoughts on that idea, @florimondmanca @JayH5? |
I think a healthier alternative might be to completely review how Starlette works wrt structured concurrency. We've had discussions about this about background tasks, as well as this Something may have to break, but it's not clear either if we have to break anything, or just change default recommendations. For example I think you mentioned starting to discourage the use of Either way, I'm somewhat in favor of keeping the status quo pre-0.13.7, i.e. accepting this PR and letting " Then we might need to start a wider conversation about structured concurrency principles applied to Starlette, aka "how do we ensure users don't shoot themselves in the foot by letting I/O resources leak unknowingly?". |
Sounds good, @florimondmanca. I agree with your comments here. I'll merge this and issue a new release issue soon. |
just for clarification's sake, @erewok, a |
No, @obataku, any time
The consumer does not affect this. |
@erewok I'm familiar with the background task behavior but I am very surprised that the entire |
It is surprising behavior. My own recommendation is to avoid |
This PR reverts the
Queue(maxsize=1)
fix forBaseHTTPMiddleware
middleware classes and streaming responses.Some users were relying on behavior where the response object would be fully evaluated within their middleware based on
BaseHTTPMiddleware
. (Of course, this was a problem forStreamingResponse
s with this middleware, because they were also being loaded fully into memory.)The
maxsize=1
fix released in version0.13.7
explicitly prevented the response object from being fully evaluated until laterawait
calls, but any users who were dropping this response for any other created inside their middleware were likely to see pending tasks accumulate.The question is now, which is a more important bug to fix (these problems are in conflict):
StreamingResponse
withBaseHTTPMiddleware
, their response is loaded entirely into memory, orBaseHTTPMiddleware
.This PR moves to fix the second by reverting the
maxsize
change, but this also resurrects the first problem.See issue #1022 and issue #1012