On Jun 25, 2010, at 9:26 AM, jgarbers wrote:
> I'm using SQLA in a CherryPy / WSGI--based application running behind
> Apache2. The database is hosted on Amazon RDS (MySQL). Recently I've
> noticed several errors like this in my logs:
>
> [error] Exception AttributeError: AttributeError("'NoneType' object
> has no attribute 'pop'",) in <bound method InstanceState._cleanup of
> <sqlalchemy.orm.state.InstanceState object at 0xb9a6718c>> ignored
>
> I'm using a CherryPy tool from here:
>
> http://code.google.com/p/webpyte/source/browse/trunk/webpyte/sqlalchemy_tool.py?r=198
>
> to automatically roll back transactions if there's an exception during
> a CherryPy request.
>
> Checking RDS monitoring, it seems that the number of open database
> transactions is going up slowly over time, perhaps in conjunction with
> the errors noted above. Restarting Apache releases all of the
> connections.
>
> It seems likely that the errors are related to the "leak" of database
> connections. Can anyone verify that, and/or suggest why I might be
> getting the errors shown?
>
> Thanks very much for any help you can offer!
The warning there is a GC related condition, where weakref callbacks are being
invoked on objects that are already half-torn down. No connection resources
are used within these weakref callbacks at the ORM level, and these are not the
source of your issue.
Beyond that, assuming you're using the ORM, and are ensuring that you fully
exhaust any row-based result sets that you get from Session.execute(), all
connections are returned to the pool explicitly without reliance on GC.
Connections returned to the pool have rollback() invoked on them
unconditionally.
The pool itself is actually not capable of slowly "leaking" connections - if
you check out too many connections past configured limits (with a default of
15), you'll get an extremely explicit error message and your application will
not continue to function.
Therefore, the most common reason for connections continuing to be opened is
the generation of an arbitrary numnber of engines with create_engine(). There
should be only one of these per process per database, and if engines need to be
removed in the middle of the application, the dispose() method should be called.
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en.