[FIX] sql_db: closing a closed connection is not allowed in psycopg2 2.4.4 and earlier

Having the connections automatically reaped by
psycopg2 is not guaranteed to happen all the
time, so we still need to take extra steps
to forece-close them

bzr revid: odo@openerp.com-20130215113751-12kwmfynyt43qs57
This commit is contained in:
Olivier Dony 2013-02-15 12:37:51 +01:00
parent 94715ccbec
commit e464e1231d
1 changed files with 3 additions and 1 deletions

View File

@ -404,7 +404,9 @@ class ConnectionPool(object):
cnx.reset()
except psycopg2.OperationalError:
self._debug('Cannot reset connection at index %d: %r', i, cnx.dsn)
cnx.close()
# psycopg2 2.4.4 and earlier do not allow closing a closed connection
if cnx.closed:
cnx.close()
if cnx.closed:
self._connections.pop(i)