From 48b82aebc3cda2ae9638f0922eea646288b45c72 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Wed, 5 Mar 2014 18:14:09 -0500 Subject: [PATCH] - Fixed small issue in :class:`.SingletonThreadPool` where the current connection to be returned might get inadvertently cleaned out during the "cleanup" process. Patch courtesy jd23. --- doc/build/changelog/changelog_09.rst | 7 +++++++ lib/sqlalchemy/pool.py | 6 +++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/doc/build/changelog/changelog_09.rst b/doc/build/changelog/changelog_09.rst index 1591872cdf..12b7c85836 100644 --- a/doc/build/changelog/changelog_09.rst +++ b/doc/build/changelog/changelog_09.rst @@ -14,6 +14,13 @@ .. changelog:: :version: 0.9.4 + .. change:: + :tags: bug, pool + + Fixed small issue in :class:`.SingletonThreadPool` where the current + connection to be returned might get inadvertently cleaned out during + the "cleanup" process. Patch courtesy jd23. + .. change:: :tags: bug, ext, py3k diff --git a/lib/sqlalchemy/pool.py b/lib/sqlalchemy/pool.py index af9b8fcbca..59c1e614a2 100644 --- a/lib/sqlalchemy/pool.py +++ b/lib/sqlalchemy/pool.py @@ -817,7 +817,7 @@ class SingletonThreadPool(Pool): self._all_conns.clear() def _cleanup(self): - while len(self._all_conns) > self.size: + while len(self._all_conns) >= self.size: c = self._all_conns.pop() c.close() @@ -837,9 +837,9 @@ class SingletonThreadPool(Pool): pass c = self._create_connection() self._conn.current = weakref.ref(c) - self._all_conns.add(c) - if len(self._all_conns) > self.size: + if len(self._all_conns) >= self.size: self._cleanup() + self._all_conns.add(c) return c -- 2.47.3