#15802: Django stops functioning when the database (PostgreSQL) closes the connection -------------------------------------+------------------------------------- Reporter: Rick.van.Hattem@… | Owner: nobody Type: Bug | Status: new Milestone: | Component: Database layer Version: 1.3 | (models, ORM) Keywords: database, postgres, | Severity: Normal postgresql, connection, closed | Triage Stage: Unreviewed Has patch: 0 | -------------------------------------+------------------------------------- In some cases (database restart, network connection lost, hard pgBouncer restart, etc...) the connection to the database is lost without giving Django a notification.
Currently Django doesn't handle that very gracefully... it just keeps trying to close an already closed connection (and gets errors because of that) so after you've somehow lost your database connection for a bit you have to restart all of your mod_wsgi processes (means executing a reload command on 5 servers for me right now) before Django starts working again. The stacktrace: {{{#!python Traceback (most recent call last): File "django/core/handlers/wsgi.py", line 267, in __call__ signals.request_finished.send(sender=self.__class__) File "django/dispatch/dispatcher.py", line 162, in send response = receiver(signal=self, sender=sender, **named) File "django/db/__init__.py", line 84, in close_connection conn.close() File "django/db/backends/__init__.py", line 72, in close self.connection.close() InterfaceError: connection already closed }}} Proposed patch, replace the `close()` method in `django/db/backends/__init__.py` so it becomes this: {{{#!python def close(self): if self.connection is not None: try: self.connection.close() self.connection = None except InterfaceError: self.connection = None raise }}} I see no valid reason for giving a non-recoverable error while closing the database connection. Yes, something is wrong and yes, the exception can be shown. But looping the error is completely futile here. -- Ticket URL: <http://code.djangoproject.com/ticket/15802> Django <http://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 this group at http://groups.google.com/group/django-updates?hl=en.