mozilla/socorro — pull request #229 by twobraids (2011-12-15 16:21:02+00:00)
Title: Fixes Bug 710904 - refactors to not use setdefault

It seems that all Socorro code that uses internal database pooling (processor, monitor, middleware, etc) may be suffering a bug with that cause spurious unused database connections. This bug has likely existed since 2008.

In socorro/database/database.py there is a connection pool that uses a dict as the cache for connections. It uses the setdefault dict method to see if there is named connection entry already existing. If not, the default value is a new connection. However, Python doesn't short circuit the second parameter of the setdefault call if a connection is found. That means that a new connection is made and then ignored each time a connection is fetched from the pool.

This fix eliminates the use of setdefault. Included are new tests to make sure that the number of connection attempts is precisely what is expected.