v5.0.0/Mac Crash on db connection close

Bug #330999 reported by Fabien Lydoire @ Taktik
12
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Odoo Server (MOVED TO GITHUB)
Status tracked in Trunk
5.0
Fix Released
High
Christophe Simonis (OpenERP)
Trunk
Fix Released
High
Christophe Simonis (OpenERP)

Bug Description

I'm running the server on Mac OS X Leopard 10.5.6, using python 2.5 provided by the system and a few other modules I compiled myself.

Trying to connect to the data base raises the following error

INFO:web-services:the server is running, waiting for connections...
INFO:dbpool:Connecting to template1
INFO:dbpool:Closing all connections to template1
Closing connection <connection>
Bus error

I tried with previous versions and it works with v5 RC1 which still used psycopg (1).
With RC2, psycopg2 has been used and the code of sql_db.py has been changed too.

Debugging, it seems that the "wrapper" method from sql_db.py is called over and over, leading to a stack overflow and an app crash.

  def check(f):
        from tools.func import wraps

        @wraps(f)
        def wrapper(self, *args, **kwargs):
            if not hasattr(self, '_obj'):
                raise psycopg2.ProgrammingError('Unable to use the cursor after having closing it')
            return f(self, *args, **kwargs)
        return wrapper

Related branches

Revision history for this message
Fabien Lydoire @ Taktik (fl-taktik) wrote :

I just patched sql_db.py.
I know it's an horrible fix, it raises exceptions, but it breaks the infinite loop.
I hope that will help the OpenERP Team to make a better fix.

         @wraps(f)
         def wrapper(self, *args, **kwargs):
- if not hasattr(self, '_obj'):
+ if not (f.func_name=='__getattr__' and args==('_obj',)) and not hasattr(self, '_obj'):
                 raise psycopg2.ProgrammingError('Unable to use the cursor after having closing it')
             return f(self, *args, **kwargs)
         return wrapper

     @check
     def __getattr__(self, name):
- return getattr(self._obj, name)
+ if name!='_obj':
+ return getattr(self._obj, name)
+ else:
+ return None

Revision history for this message
mark.a.m (mark-a-m) wrote :

The problem here is, given the case that some callee (e.g. __del__) wants to see if aCursor contains an attribute named '_obj' hasattr calls getattr to see if it raises an exception, getattr in turn calls __getattr__ which is wrapped in checks wrapper method which uses hasattr triggering an infinite recursion.

--- sql_db.py.bak 2009-03-05 22:59:42.000000000 +0100
+++ sql_db.py 2009-03-06 00:12:34.000000000 +0100
@@ -181,9 +181,11 @@
     def rollback(self):
         return self._cnx.rollback()

- @check
     def __getattr__(self, name):
- return getattr(self._obj, name)
+ if name =='_obj':
+ raise AttributeError("No attribute named _obj")
+ else:
+ return getattr(self._obj, name)

 class ConnectionPool(object):
     def __init__(self, pool, dbname):

mark.a.m (mark-a-m)
Changed in openobject-server:
status: New → Confirmed
Revision history for this message
mark.a.m (mark-a-m) wrote :

Bug has been confirmed for mac and freebsd, please see the attached patch for a fix and explanation.

Changed in openobject-server:
assignee: nobody → fabian-openerp
Revision history for this message
Fabien Lydoire @ Taktik (fl-taktik) wrote :

I confirm the patch solved the problem on Mac OS X. Thanks !

mark.a.m (mark-a-m)
Changed in openobject-server:
assignee: fabian-openerp → fp-tinyerp
Revision history for this message
Santi Argüeso(Pexego) (santiago-pexego) wrote :

I've tested the patch on a FreeBSD 7_STABLE server running 5.0.0-3 and now it works.

thank you!

Revision history for this message
mark.a.m (mark-a-m) wrote : Re: [Bug 330999] Re: v5.0.0/Mac Crash on db connection close

Christophe (OpenERP) wrote:
> ** Changed in: openobject-server/trunk
> Assignee: Fabien (Open ERP) (fp-tinyerp) => Christophe (OpenERP) (kangol)

If you need additional information about the bug I'd be glad to help. It
should be quite clear that '@check' triggers a potential infinite recursion.

Regards, Mark

Revision history for this message
Christophe Simonis (OpenERP) (kangol) wrote :

On 03.04.2009 19:13, mark.a.m wrote:
> Christophe (OpenERP) wrote:
>> ** Changed in: openobject-server/trunk
>> Assignee: Fabien (Open ERP) (fp-tinyerp) => Christophe (OpenERP) (kangol)
>
> If you need additional information about the bug I'd be glad to help. It
> should be quite clear that '@check' triggers a potential infinite recursion.
>
> Regards, Mark
>
Not anymore.

--
Christophe Simonis
Developer
OpenERP - Tiny sprl
Chaussée de Namur, 40
B-1367 Gérompont
Tel: +32.81.81.37.00
Web: http://openerp.com
Blog: http://christophe-simonis-at-tiny.blogspot.com

TinyERP: making ERP Tiny and Easy To use
   -- Sidahmed Dine, 2006

Revision history for this message
Olivier Dony (Odoo) (odo-openerp) wrote :

updating status.. all 5.0 fixes have been ported to 6.0 a while ago

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.