File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ()
You can’t perform that action at this time.
0 commit comments