#19519: Django fails to close db connections at end of request-response cycle -------------------------------------+------------------------------------- Reporter: amosonn@… | Owner: nobody Type: Bug | Status: new Component: Database layer | Version: 1.4 (models, ORM) | Resolution: Severity: Normal | Triage Stage: Keywords: connection, | Unreviewed managment, closing, mysql, | Needs documentation: 0 innodb, signal, generator | Patch needs improvement: 0 Has patch: 0 | UI/UX: 0 Needs tests: 0 | Easy pickings: 0 | -------------------------------------+-------------------------------------
Comment (by apollo13): Raising this issue to "release blocker" since streaming responses are new in 1.5 and somewhat broken in that regard! I attached a project which demonstrates the issue, see the following server log: {{{ <sqlite3.Connection object at 0x17234b8> ------------------------ () {'signal': <django.dispatch.dispatcher.Signal object at 0x149e1d0>, 'sender': <class 'django.core.handlers.wsgi.WSGIHandler'>} ------------------------ [29/Dec/2012 03:54:12] "GET /testing/ HTTP/1.1" 200 15 <sqlite3.Connection object at 0x17234b8> ------------------------ () {'signal': <django.dispatch.dispatcher.Signal object at 0x149e1d0>, 'sender': <class 'django.core.handlers.wsgi.WSGIHandler'>} ------------------------ None request already finished: True [29/Dec/2012 03:54:16] "GET /testing_generator/ HTTP/1.1" 200 18 }}} What does this mean? When using StreamingHttpResponse the request_finished signal is sent before the response is actually generated, meaning database connections are already closed and a new query inside the iterator would cause a new connection to open. A fix might be something along the lines of http://werkzeug.pocoo.org/docs/wsgi/#werkzeug.wsgi.ClosingIterator -- eg returning the response and issuing the request_finished signal after the upstream wsgi gateway exhausted the iterator. -- Ticket URL: <https://code.djangoproject.com/ticket/19519#comment:2> 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 post to this group, send email to django-updates@googlegroups.com. To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.