#30565: Close StreamingHttpResponse content immediately after iterating it
-------------------------------------+-------------------------------------
Reporter: Chris Jerdonek | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: HTTP handling | Version: master
Severity: Normal | Resolution:
Keywords: HttpResponse, | Triage Stage:
streaming, StreamingHttpResponse | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Chris Jerdonek):
> We're saying that's not the case?
A few comments on this. My first idea to make sure my content stream was
closed was to subclass `StreamingHttpResponse` and close my content stream
inside a new `StreamingHttpResponse.close()` implementation, precisely
because of that code comment you found. But then I found that
`HttpResponseBase.close()` wasn't getting called for some reason. Indeed,
`HttpResponseBase.close()` already calls `close()` on everything inside
`self._closable_objects`, so it shouldn't have been necessary for me to
subclass `StreamingHttpResponse` if `HttpResponseBase.close()` was already
getting called.
And then I saw the [https://code.djangoproject.com/ticket/25725#comment:1
comment] in #25725 saying:
> If i remember Jacob's talk correctly not even all WSGI server call
close.
So I thought that was the coming into play.
But now I'm seeing that when I use the approach I suggested of wrapping
the content stream with an iterator that closes the underlying content
stream immediately after it has been exhausted, `HttpResponseBase.close()`
''does'' get closed. In other words, not closing the underlying content
stream was causing `HttpResponseBase.close()` not to be called.
So there's an argument for what I'm suggesting independent of whether
`HttpResponseBase.close()` can be relied upon to close. Put another way,
implementing what I'm suggesting helps that code comment be true, at least
in the case I ran into.
--
Ticket URL: <https://code.djangoproject.com/ticket/30565#comment:4>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/067.98504973510f3e2fe2433910a1358f4f%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.