From 1156aee52a8950c608054ba883fcf15783c1be92 Mon Sep 17 00:00:00 2001 From: Florent Xicluna Date: Thu, 17 Nov 2011 10:33:35 +0100 Subject: [PATCH] [FIX] discard closed connections. Restart not required anymore when connection is lost. bzr revid: florent.xicluna@wingo.ch-20111117093335-6t16181mqt49z7bi --- openerp/sql_db.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/openerp/sql_db.py b/openerp/sql_db.py index ab92d7cc21d..63ab2a13fb9 100644 --- a/openerp/sql_db.py +++ b/openerp/sql_db.py @@ -175,18 +175,18 @@ class Cursor(object): self._cnx = pool.borrow(dsn(dbname)) self._obj = self._cnx.cursor(cursor_factory=psycopg1cursor) - self.__closed = False # real initialisation value - self.autocommit(False) if self.sql_log: self.__caller = frame_codeinfo(currentframe(),2) else: self.__caller = False + self.__closed = False # real initialisation value + self.autocommit(False) self.__closer = False self._default_log_exceptions = True def __del__(self): - if not self.__closed: + if not self.__closed and not self._cnx.closed: # Oops. 'self' has not been closed explicitly. # The cursor will be deleted by the garbage collector, # but the database connection is not put back into the connection @@ -390,6 +390,10 @@ class ConnectionPool(object): # free leaked connections for i, (cnx, _) in tools.reverse_enumerate(self._connections): + if cnx.closed: + self._connections.pop(i) + self._debug('Removing closed connection at index %d: %r', i, cnx.dsn) + continue if getattr(cnx, 'leaked', False): delattr(cnx, 'leaked') self._connections.pop(i)