diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-03-05 15:37:00 -0500 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-02-26 12:04:11 -0500 |
| commit | f78db5e1f68d6b2fb6a7acc04036f682d9a22974 (patch) | |
| tree | 199611705f8944f28ef985ed2011ba0577ba671e /lib/sqlalchemy | |
| parent | e15c53716b9f59c7c666c77d1e8b8d82538036a3 (diff) | |
| download | sqlalchemy-f78db5e1f68d6b2fb6a7acc04036f682d9a22974.tar.gz | |
Don't call pre_ping for fresh connection
The pool "pre-ping" feature has been refined to not invoke for a DBAPI
connection that was just opened in the same checkout operation. pre ping
only applies to a DBAPI connection that's been checked into the pool
and is being checked out again.
Fixes: #4524
Change-Id: Ibe3dfb709dbdc24aa94e96513cfbea456c33b895
Diffstat (limited to 'lib/sqlalchemy')
| -rw-r--r-- | lib/sqlalchemy/pool/base.py | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/lib/sqlalchemy/pool/base.py b/lib/sqlalchemy/pool/base.py index bdb981699..b53f0d7dd 100644 --- a/lib/sqlalchemy/pool/base.py +++ b/lib/sqlalchemy/pool/base.py @@ -360,6 +360,8 @@ class _ConnectionRecord(object): self.__connect(first_connect_check=True) self.finalize_callback = deque() + fresh = False + fairy_ref = None starttime = None @@ -574,6 +576,7 @@ class _ConnectionRecord(object): connection = pool._invoke_creator(self) pool.logger.debug("Created new connection %r", connection) self.connection = connection + self.fresh = True except Exception as e: pool.logger.debug("Error on connect(): %s", e) raise @@ -699,7 +702,6 @@ class _ConnectionFairy(object): if fairy.connection is None: raise exc.InvalidRequestError("This connection is closed") fairy._counter += 1 - if ( not pool.dispatch.checkout and not pool._pre_ping ) or fairy._counter != 1: @@ -712,22 +714,30 @@ class _ConnectionFairy(object): # here. attempts = 2 while attempts > 0: + connection_is_fresh = fairy._connection_record.fresh + fairy._connection_record.fresh = False try: if pool._pre_ping: - if fairy._echo: - pool.logger.debug( - "Pool pre-ping on connection %s", fairy.connection - ) - - result = pool._dialect.do_ping(fairy.connection) - if not result: + if not connection_is_fresh: if fairy._echo: pool.logger.debug( - "Pool pre-ping on connection %s failed, " - "will invalidate pool", + "Pool pre-ping on connection %s", fairy.connection, ) - raise exc.InvalidatePoolError() + result = pool._dialect.do_ping(fairy.connection) + if not result: + if fairy._echo: + pool.logger.debug( + "Pool pre-ping on connection %s failed, " + "will invalidate pool", + fairy.connection, + ) + raise exc.InvalidatePoolError() + elif fairy._echo: + pool.logger.debug( + "Connection %s is fresh, skipping pre-ping", + fairy.connection, + ) pool.dispatch.checkout( fairy.connection, fairy._connection_record, fairy |
