diff options
| author | mike bayer <mike_mp@zzzcomputing.com> | 2022-12-14 20:40:48 +0000 |
|---|---|---|
| committer | Gerrit Code Review <gerrit@ci3.zzzcomputing.com> | 2022-12-14 20:40:48 +0000 |
| commit | f954672103892b165097d70124d7fa354ef8bd4f (patch) | |
| tree | 76efbe366b9cfc1b08f20f613cf2279b7c4b0d1c /lib/sqlalchemy | |
| parent | a8d76cff39dbaf6354d42d35cd68332df469d124 (diff) | |
| parent | 6221c53ca86787e2de55de8b203658adcdf3b8a1 (diff) | |
| download | sqlalchemy-f954672103892b165097d70124d7fa354ef8bd4f.tar.gz | |
Merge "catch all BaseException in pool and revert failed checkouts" into main
Diffstat (limited to 'lib/sqlalchemy')
| -rw-r--r-- | lib/sqlalchemy/pool/base.py | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/lib/sqlalchemy/pool/base.py b/lib/sqlalchemy/pool/base.py index 47c39791c..7b211afd9 100644 --- a/lib/sqlalchemy/pool/base.py +++ b/lib/sqlalchemy/pool/base.py @@ -380,10 +380,12 @@ class Pool(log.Identified, event.EventTarget): self._dialect.do_terminate(connection) else: self._dialect.do_close(connection) - except Exception: + except BaseException as e: self.logger.error( "Exception closing connection %r", connection, exc_info=True ) + if not isinstance(e, Exception): + raise def _create_connection(self) -> ConnectionPoolEntry: """Called by subclasses to create a new ConnectionRecord.""" @@ -714,9 +716,11 @@ class _ConnectionRecord(ConnectionPoolEntry): try: dbapi_connection = rec.get_connection() - except Exception as err: + except BaseException as err: with util.safe_reraise(): rec._checkin_failed(err, _fairy_was_created=False) + + # not reached, for code linters only raise echo = pool._should_log_debug() @@ -738,7 +742,7 @@ class _ConnectionRecord(ConnectionPoolEntry): return fairy def _checkin_failed( - self, err: Exception, _fairy_was_created: bool = True + self, err: BaseException, _fairy_was_created: bool = True ) -> None: self.invalidate(e=err) self.checkin( @@ -893,7 +897,7 @@ class _ConnectionRecord(ConnectionPoolEntry): self.dbapi_connection = connection = pool._invoke_creator(self) pool.logger.debug("Created new connection %r", connection) self.fresh = True - except Exception as e: + except BaseException as e: with util.safe_reraise(): pool.logger.debug("Error on connect(): %s", e) else: @@ -1271,6 +1275,7 @@ class _ConnectionFairy(PoolProxiedConnection): # here. attempts = 2 + while attempts > 0: connection_is_fresh = fairy._connection_record.fresh fairy._connection_record.fresh = False @@ -1323,7 +1328,7 @@ class _ConnectionFairy(PoolProxiedConnection): fairy.dbapi_connection = ( fairy._connection_record.get_connection() ) - except Exception as err: + except BaseException as err: with util.safe_reraise(): fairy._connection_record._checkin_failed( err, @@ -1341,6 +1346,21 @@ class _ConnectionFairy(PoolProxiedConnection): raise attempts -= 1 + except BaseException as be_outer: + with util.safe_reraise(): + rec = fairy._connection_record + if rec is not None: + rec._checkin_failed( + be_outer, + _fairy_was_created=True, + ) + + # prevent _ConnectionFairy from being carried + # in the stack trace, see above + del fairy + + # never called, this is for code linters + raise pool.logger.info("Reconnection attempts exhausted on checkout") fairy.invalidate() |
