connection already closed error

From: Mark Theisen <mark(dot)theisen(at)digitecinc(dot)com>
To: "psycopg(at)postgresql(dot)org" <psycopg(at)postgresql(dot)org>
Subject: connection already closed error
Date: 2011-10-18 14:32:13
Message-ID: 7197F80C5AE6E943AF2CC4067B22FBD4BD0DD3F05E@OMALINMAIL01.lindsaymfg.local
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: psycopg

Hi all,

I am using python2.6 with twisted 10.1.0 and psycopg2 2.2.1. We are also using pgpooler with transaction pool mode set. I am using the twisted ConnectionPool and twistedpg.py, which is:

from psycopg2 import *
from psycopg2 import _psycopg as _2psycopg
from psycopg2.extensions import connection as _2connection
from psycopg2.extras import RealDictCursor

del connect
def connect(*args, **kwargs):
kwargs['connection_factory'] = connection
return _2psycopg.connect(*args, **kwargs)

class connection(_2connection):
def cursor(self):
return _2connection.cursor(self, cursor_factory=RealDictCursor)

I connect to pgpooler with:
dbpool = ConnectionPool("twistedpg", self.DSN, cp_reconnect=cp_reconnect, cp_openfun = self.connect_func, **kwords)

I am getting this error when we restart pgpool:

Traceback (most recent call last):
File "/usr/lib/python2.6/dist-packages/twisted/python/context.py", line 37, in callWithContext
return func(*args,**kw)
File "/usr/lib/python2.6/dist-packages/twisted/enterprise/adbapi.py", line 436, in _runInteraction
conn.rollback()
File "/usr/lib/python2.6/dist-packages/twisted/enterprise/adbapi.py", line 65, in rollback
self._pool.disconnect(self._connection)
File "/usr/lib/python2.6/dist-packages/twisted/enterprise/adbapi.py", line 412, in disconnect
self._close(conn)
--- <exception caught here> ---
File "/usr/lib/python2.6/dist-packages/twisted/enterprise/adbapi.py", line 420, in _close
conn.close()
psycopg2.InterfaceError: connection already closed

This error keeps repeating for about 3 hours, even though the pooler was back up in running within a minute.

Would a possible solution be to change twistedpg.py to:

from psycopg2 import *
from psycopg2 import _psycopg as _2psycopg
from psycopg2.extensions import connection as _2connection
from psycopg2.extras import RealDictCursor

del connect
def connect(*args, **kwargs):
kwargs['connection_factory'] = connection
return _2psycopg.connect(*args, **kwargs)

class connection(_2connection):
def cursor(self):
return _2connection.cursor(self, cursor_factory=RealDictCursor)

def close(self):
try:
_2connection.close(self)
except psycopg2.InterfaceError:
pass

Thanks for all the help,
Mark

Responses

Browse psycopg by date

  From Date Subject
Next Message Daniele Varrazzo 2011-10-18 15:11:35 Re: connection already closed error
Previous Message Frank Kauff 2011-10-18 12:08:44 Error with Zope 2.13.8