Opened 3 years ago
Closed 3 years ago
#33152 closed Cleanup/optimization (invalid)
Document the fact that a DB connection can be closed mid-request when a HTTP client disconnects prematurely
Reported by: | Rich | Owned by: | nobody |
---|---|---|---|
Component: | Documentation | Version: | 3.2 |
Severity: | Normal | Keywords: | |
Cc: | Florian Apolloner | Triage Stage: | Unreviewed |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I've described and diagnosed an issue that has caused me headaches for some weeks here:
This took a lot of effort to investigate, and I'd like to avoid others having to do the same.
I think the official doc needs to explain that a HTTP response can be closed DURING the handling of a request - when this happens, seemingly random django.db.utils.InterfaceErrors can be thrown.
These are very difficult to debug because of the way the HttpResponse.close() code has run asynchronously and invisibly.
It may be that the Django code could also benefit from some changes...the HTTP client closing the connection early is after all within the scope of 'normal' behaviour - right now quite what happens depends on whether a transaction is in effect or not, as well as other, essentially arbitrary settings. Some sort of normalised behaviour would be great, but I don't see how to implement it without setting some sort of global flag on close which is regularly checked somewhere...
Change History (1)
comment:1 by , 3 years ago
Cc: | added |
---|---|
Resolution: | → invalid |
Status: | new → closed |
Type: | Uncategorized → Cleanup/optimization |
HttpResponse.close()
is called at the end of a request by the WSGI server. I'm not sure what is callingclose()
in your case but I don't see why and where Django is at fault. Handling of an HTTP request can be interrupted in many ways and Django doesn't do anything unusual in this matter. IMO, Django docs are not the best place to explain this.