#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)                      |   Keywords:  connection, managment,
     Severity:  Normal               |  closing, mysql, innodb, signal,
 Triage Stage:  Unreviewed           |  generator
Easy pickings:  0                    |  Has patch:  0
                                     |      UI/UX:  0
-------------------------------------+-------------------------------------
 Under some circumstances (I'll get to guesses about this in the end), the
 db connection isn't closed at the end of the request, and resurfaces later
 on to service another request. Thus, one request writes to the database,
 and then the next request tries to look for that data and fails, because
 it uses an outdated connection that hasn't yet been notified of the db
 change (per [http://www.python.org/dev/peps/pep-0249/#connection-objects
 pep-249], different connections aren't required to see the same data.) The
 workaround solution for this is to add a django.db.connection.close()
 before that query, which brings to mind
 [https://code.djangoproject.com/ticket/13533 bug #13533]. Similarly, This
 bug manifests on mysql innodb; but I haven't checked other databases, so
 this might just be coincidence. It is also possible that the non-closing
 connection bug exists for all back-ends, but that auto-commit isn't enough
 to prevent the damage only on mysql innodb.

 The situation under which I've seen these connections retained is when
 sending an HttpResponse with a generator for content. It might be that
 when sending such content, the following lines (django.db:44-47)
 {{{
 def close_connection(**kwargs):
     for conn in connections.all():
         conn.close()
 signals.request_finished.connect(close_connection)
 }}}
 which are supposed to make sure the connection closes, don't work, because
 the signal isn't raised. It is, however, still a riddle how the old
 connection gets attached to a new request.
 [https://code.djangoproject.com/ticket/19117 Bug #19117] might also be
 related to this.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/19519>
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.


Reply via email to