Skip to content

Commit 48c97ab

Browse files
committed
Adjusting to make sure we dont return closed connections
1 parent 5ffd9e2 commit 48c97ab

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

sqlobject/dbconnection.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,20 @@ def getConnection(self):
344344
if self._pool is not None:
345345
s += ' pool=[%s]' % ', '.join([str(self._connectionNumbers[id(v)]) for v in self._pool])
346346
self.printDebug(conn, s, 'Pool')
347+
348+
# Safeguard to make sure we dont return a closed connection.
349+
# If the connection is closed, delete it and start recursive execution.
350+
if hasattr(conn, 'closed') and conn.closed:
351+
if self.debug:
352+
s = 'ACQUIRED CONNECTION IS CLOSED'
353+
if self._pool is not None:
354+
s += ' pool=[%s]' % ', '.join([str(self._connectionNumbers[id(v)]) for v in self._pool])
355+
self.printDebug(conn, s, 'Pool')
356+
357+
del conn
358+
self._poolLock.release()
359+
return self.getConnection()
360+
347361
return conn
348362
finally:
349363
self._poolLock.release()

sqlobject/tests/dbs_data.tmp

32 KB
Binary file not shown.

0 commit comments

Comments
 (0)