[FIX] sql_db: free dead database connections

lp bug: https://launchpad.net/bugs/905257 fixed

bzr revid: chs@openerp.com-20130214135227-x6lzy3gj0s75ssmw
This commit is contained in:
Christophe Simonis 2013-02-14 14:52:27 +01:00
parent 89e569c17e
commit 94715ccbec
1 changed files with 8 additions and 2 deletions

View File

@ -3,7 +3,7 @@
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
# Copyright (C) 2010-2011 OpenERP s.a. (<http://openerp.com>).
# Copyright (C) 2010-2013 OpenERP s.a. (<http://openerp.com>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
@ -398,8 +398,14 @@ class ConnectionPool(object):
def borrow(self, dsn):
self._debug('Borrow connection to %r', dsn)
# free leaked connections
# free dead and leaked connections
for i, (cnx, _) in tools.reverse_enumerate(self._connections):
try:
cnx.reset()
except psycopg2.OperationalError:
self._debug('Cannot reset connection at index %d: %r', i, cnx.dsn)
cnx.close()
if cnx.closed:
self._connections.pop(i)
self._debug('Removing closed connection at index %d: %r', i, cnx.dsn)