Merge lp:~openerp-dev/openobject-server/7.0-rstcnx-chs into lp:openobject-server/7.0

Proposed by Christophe Simonis (OpenERP)
Status: Superseded
Proposed branch: lp:~openerp-dev/openobject-server/7.0-rstcnx-chs
Merge into: lp:openobject-server/7.0
Diff against target: 30 lines (+10/-2)
1 file modified
openerp/sql_db.py (+10/-2)
To merge this branch: bzr merge lp:~openerp-dev/openobject-server/7.0-rstcnx-chs
Reviewer Review Type Date Requested Status
OpenERP Core Team Pending
Review via email: mp+148455@code.launchpad.net

This proposal has been superseded by a proposal from 2013-02-16.

To post a comment you must log in.
Revision history for this message
Olivier Dony (Odoo) (odo-openerp) wrote :

LGTM, but after testing with older psycopg2 versions I had to add a check before calling cnx.close(), as close() used to raise an Exception if the connection was already marked as closed (that is, before psycopg2 2.4.5)

Note that reset() was introduced in psycopg2 2.0.12, so we might want to make the requirement explicit in setup.py. For 7.0 we actually require the `current version from debian stable as of the release date`, and this has been 2.2.1 since 2010.

See also the rationale for this patch in the comments on https://code.launchpad.net/~florent.x/openobject-server/trunk-bug-905257-fix-reconnect/+merge/132149

4842. By Olivier Dony (Odoo)

[FIX] sql_db: immediately remove the connections from the pool when detected to be dead

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'openerp/sql_db.py'
2--- openerp/sql_db.py 2012-12-14 12:43:10 +0000
3+++ openerp/sql_db.py 2013-02-15 11:40:26 +0000
4@@ -3,7 +3,7 @@
5 #
6 # OpenERP, Open Source Management Solution
7 # Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
8-# Copyright (C) 2010-2011 OpenERP s.a. (<http://openerp.com>).
9+# Copyright (C) 2010-2013 OpenERP s.a. (<http://openerp.com>).
10 #
11 # This program is free software: you can redistribute it and/or modify
12 # it under the terms of the GNU Affero General Public License as
13@@ -398,8 +398,16 @@
14 def borrow(self, dsn):
15 self._debug('Borrow connection to %r', dsn)
16
17- # free leaked connections
18+ # free dead and leaked connections
19 for i, (cnx, _) in tools.reverse_enumerate(self._connections):
20+ try:
21+ cnx.reset()
22+ except psycopg2.OperationalError:
23+ self._debug('Cannot reset connection at index %d: %r', i, cnx.dsn)
24+ # psycopg2 2.4.4 and earlier do not allow closing a closed connection
25+ if cnx.closed:
26+ cnx.close()
27+
28 if cnx.closed:
29 self._connections.pop(i)
30 self._debug('Removing closed connection at index %d: %r', i, cnx.dsn)