Hi,

I'm trying to understand dbconnection.py but I have some questions regarding
this module...

My first question is related to releaseConnection() and the _pool variable:
#--------------------------------------------------------------------------
         if self._pool is not None:
             if conn not in self._pool:
                 # @@: We can get duplicate releasing of connections with
                 # the __del__ in Iteration (unfortunately, not sure why
                 # it happens)
                 self._pool.insert(0, conn)
         else:
             conn.close()
#--------------------------------------------------------------------------

First of all, I think there is a locking error because _pool is modified but
_poolLock is not acquired before. This would be no problem is
releaseConnection() is always called from methods which do acquire this lock (in
this case I really, really think this should be noted in a comment!).

As far as I can see, releaseConnection() is called from:
- Iteration._cleanup
- Transaction._makeObsolete
- DBAPI._runWithConnection

At least _runWithConnection() is called from several public methods (query*)
which do not acquire locks. Therefore locking should be done in
releaseConnection().

Checking for possible deadlocks:
_makeObsolete() is only called from rollback() so no locks here.
_cleanup() is called from next() and __del__(), no obvious locks.

Beware: I did only check method calls inside dbconnection.py. If private methods
(which are prefixed by the underscore) are called from other modules, the whole
thing has to be re-examined!

But even with proper locking, I do not understand the intentions of this code:
#--------------------------------------------------------------------------
         if self._pool is not None:
             if conn not in self._pool:
                 # @@: We can get duplicate releasing of connections with
                 # the __del__ in Iteration (unfortunately, not sure why
                 # it happens)
                 self._pool.insert(0, conn)
         else:
             conn.close()
#--------------------------------------------------------------------------

Why is the connection added to the pool if it is not present? Is it because 
database connections are not thread safe and must not be shared between 
multiple 
threads? How are connections closed then? Are they shut down automatically when 
the garbage collector kicks in?

After all this looking at the code, I forgot my second question... ;-)

fs




-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss

Reply via email to