[Sqlalchemy-tickets] Issue #3497: connectionrec recycle can create situation where checkout handler
Brought to you by:
zzzeek
|
From: Mike B. <iss...@bi...> - 2015-07-22 19:59:51
|
New issue 3497: connectionrec recycle can create situation where checkout handler is called w/o connect handler being successful https://bitbucket.org/zzzeek/sqlalchemy/issues/3497/connectionrec-recycle-can-create-situation Mike Bayer: ``` #!diff diff --git a/lib/sqlalchemy/pool.py b/lib/sqlalchemy/pool.py index b38aefb..9af956b 100644 --- a/lib/sqlalchemy/pool.py +++ b/lib/sqlalchemy/pool.py @@ -453,6 +453,7 @@ class _ConnectionRecord(object): for_modify(pool.dispatch).\ exec_once(self.connection, self) pool.dispatch.connect(self.connection, self) + self.info['x'] = 1 connection = None """A reference to the actual DBAPI connection being tracked. @@ -563,6 +564,8 @@ class _ConnectionRecord(object): self.connection = self.__connect() if self.__pool.dispatch.connect: self.__pool.dispatch.connect(self.connection, self) + self.info['x'] = 1 + elif self.__pool._recycle > -1 and \ time.time() - self.starttime > self.__pool._recycle: self.__pool.logger.info( @@ -587,9 +590,17 @@ class _ConnectionRecord(object): if recycle: self.__close() self.info.clear() + + # this is the fix; ensure self.connection is None first + # self.connection = None + + # here, if __connect() fails, self.connection + # is still referring to the old connection, but info is empty + # and we won't attempt a __connect() next time we are here self.connection = self.__connect() if self.__pool.dispatch.connect: self.__pool.dispatch.connect(self.connection, self) + self.info['x'] = 1 return self.connection def __close(self): @@ -718,12 +729,14 @@ class _ConnectionFairy(object): fairy._counter += 1 if not pool.dispatch.checkout or fairy._counter != 1: + assert 'x' in fairy.info return fairy # Pool listeners can trigger a reconnection on checkout attempts = 2 while attempts > 0: try: + assert fairy.info['x'] pool.dispatch.checkout(fairy.connection, fairy._connection_record, fairy) ``` then run: py.test test/engine/test_pool.py -k test_error_on_pooled_reconnect_cleanup_recycle this warrants an immediate 1.0.8 IMO, I would like to try to produce an oslo.db-level reproduction case though |