InterfaceError: Connection already closed -- is this a regression?

694 views
Skip to first unread message

onelson

unread,
Mar 2, 2011, 10:46:45 AM3/2/11
to Django users
I recently switched a project from mysql to postgres and started to
see httpd throwing intermittent 500 errors.

mod_wsgi (pid=26467): Exception occurred processing WSGI script '..../
htdocs/django.wsgi'.
Traceback (most recent call last):
File "...../lib/python2.6/site-packages/django/core/handlers/
wsgi.py", line 275, in __call__
signals.request_finished.send(sender=self.__class__)
File "...../lib/python2.6/site-packages/django/dispatch/
dispatcher.py", line 172, in send
response = receiver(signal=self, sender=sender, **named)
File "...../lib/python2.6/site-packages/django/db/__init__.py",
line 84, in close_connection
conn.close()
File "...../lib/python2.6/site-packages/django/db/backends/
__init__.py", line 79, in close
self.connection.close()
InterfaceError: connection already closed

I'm seeing this maybe every 20-30th page request.

Looking at the issues on trac, I see a handful of tickets that share
this error, however I don't see anything common between them (or my
own situation) beyond using psycopg2.
http://code.djangoproject.com/search?q=InterfaceError+connection+already+closed&noquickjump=1&ticket=on
Most of the tickets are *old*. Years old. Either this is something pg
users are familiar with and just know how to deal with, or this is a
bug (or both?)

Thoughts please!

Danny

unread,
Mar 15, 2011, 11:04:54 AM3/15/11
to Django users
I'm having the exact same issue and haven't found any answers either.
I'll update if I find something as well.

On Mar 2, 11:46 am, onelson <onel...@gmail.com> wrote:
> I recently switched a project from mysql to postgres and started to
> see httpd throwing intermittent 500 errors.
>
> mod_wsgi (pid=26467): Exception occurred processing WSGI script '..../
> htdocs/django.wsgi'.
>  Traceback (most recent call last):
>    File "...../lib/python2.6/site-packages/django/core/handlers/
> wsgi.py", line 275, in __call__
>      signals.request_finished.send(sender=self.__class__)
>    File "...../lib/python2.6/site-packages/django/dispatch/
> dispatcher.py", line 172, in send
>      response = receiver(signal=self, sender=sender, **named)
>    File "...../lib/python2.6/site-packages/django/db/__init__.py",
> line 84, in close_connection
>      conn.close()
>    File "...../lib/python2.6/site-packages/django/db/backends/
> __init__.py", line 79, in close
>      self.connection.close()
> InterfaceError: connection already closed
>
> I'm seeing this maybe every 20-30th page request.
>
> Looking at the issues on trac, I see a handful of tickets that share
> this error, however I don't see anything common between them (or my
> own situation) beyond using psycopg2.http://code.djangoproject.com/search?q=InterfaceError+connection+alre...

Russell Keith-Magee

unread,
Mar 15, 2011, 8:40:08 PM3/15/11
to django...@googlegroups.com

You're missing the third, and more likely option -- there's something
wrong with your code. I've been running MySQL and Postgres installs
for many years, and I've never encountered the problem you describe.
This isn't a case of "oh, that just happens and we live with it".

It's also possible that you have found a bug, but it's an edge case
particular to your particular usage. Looking at your stack trace,
you're getting the exception at the end of request processing when
Django tries to 'clean up' and close the connection to the database.
However, at that point, the database has already been closed. This
means that either:

* You have already (implicitly or explicitly) closed the connection
* The database connection has dropped out for some reason
* The 'end of request' signal has been fired twice.

Absent of any specific details, I can't narrow down the problem any
more than that. We would need to see some specific code to give any
more advice. If you can reduce your code to a minimal test case that
demonstrates the problem, that might help.

Yours,
Russ Magee %-)

onelson

unread,
Mar 21, 2011, 10:27:46 AM3/21/11
to Django users
I hear you, Russ.
I'll see if I can't get something more repeatable down in code, but as
I stated, it's an intermittent problem.
Didn't meant to sound like your 3rd option wasn't an option ("issues
with the code" is always an option). I just wanted to make sure this
wasn't a "postgres thing" that I simply didn't have the tribal
knowledge of.

Thanks for the input!

Regards,
Owen Nelson
Reply all
Reply to author
Forward
0 new messages