summaryrefslogtreecommitdiff
path: root/openerp/sql_db.py
diff options
context:
space:
mode:
authorOlivier Dony <odo@openerp.com>2013-02-15 13:53:13 +0100
committerOlivier Dony <odo@openerp.com>2013-02-15 13:53:13 +0100
commitb005d052d0e680026f8326cdfca98a80c3e8a92c (patch)
tree16fb07faad4c2c27f2b5150c5e8d86e9a87a67b4 /openerp/sql_db.py
parent4fef24e78180cb92a5077b0b41d51d07e34c24c5 (diff)
parente464e1231d593cb147571e2e59c337d4667054eb (diff)
[MERGE] sql_db: autodetect dead connections and discard them
lp bug: https://launchpad.net/bugs/905257 fixed bzr revid: odo@openerp.com-20130215125313-448n5b0dluei8qm3
Diffstat (limited to 'openerp/sql_db.py')
-rw-r--r--openerp/sql_db.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/openerp/sql_db.py b/openerp/sql_db.py
index 337964f3368..a41f5e5077e 100644
--- a/openerp/sql_db.py
+++ b/openerp/sql_db.py
@@ -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,16 @@ 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)
+ # 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)
self._debug('Removing closed connection at index %d: %r', i, cnx.dsn)