diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-10-07 10:09:41 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-10-07 10:09:41 -0400 |
| commit | 3ca8b453088ac6fb815e2f39c9a705b49bfb188c (patch) | |
| tree | efd74a0b90d051abe7e5871a2868c29cdbece397 /lib/sqlalchemy/pool | |
| parent | bb32b59cd4e3477402c44d70ef6b5a12827bb429 (diff) | |
| download | sqlalchemy-3ca8b453088ac6fb815e2f39c9a705b49bfb188c.tar.gz | |
Revert "Use monotonic time for pool age measurement"
This reverts commit 0220b58917b5a979891b5765f6ac5095e0368489.
I completely misread https://www.python.org/dev/peps/pep-0418/#rationale
and the accuracy of monotonic() is *worse* on windows than time.time(),
which is bizarre.
Change-Id: I2d571e268a2051bea68736507773d3904403af9e
Diffstat (limited to 'lib/sqlalchemy/pool')
| -rw-r--r-- | lib/sqlalchemy/pool/base.py | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/lib/sqlalchemy/pool/base.py b/lib/sqlalchemy/pool/base.py index 2f1959f7c..87383fef7 100644 --- a/lib/sqlalchemy/pool/base.py +++ b/lib/sqlalchemy/pool/base.py @@ -11,15 +11,16 @@ """ from collections import deque +import time import weakref from .. import event from .. import exc from .. import log from .. import util -from ..util import monotonic_time from ..util import threading + reset_rollback = util.symbol("reset_rollback") reset_commit = util.symbol("reset_commit") reset_none = util.symbol("reset_none") @@ -260,7 +261,7 @@ class Pool(log.Identified): """ rec = getattr(connection, "_connection_record", None) if not rec or self._invalidate_time < rec.starttime: - self._invalidate_time = monotonic_time() + self._invalidate_time = time.time() if _checkin and getattr(connection, "is_valid", False): connection.invalidate(exception) @@ -509,7 +510,7 @@ class _ConnectionRecord(object): self.connection, ) if soft: - self._soft_invalidate_time = monotonic_time() + self._soft_invalidate_time = time.time() else: self.__close() self.connection = None @@ -518,16 +519,23 @@ class _ConnectionRecord(object): recycle = False # NOTE: the various comparisons here are assuming that measurable time - # passes between these state changes. on Python 2, we are still using - # time.time() which is not guaranteed to have millisecondsecond - # precision, i.e. on Windows. For Python 3 we now use monotonic_time(). - + # passes between these state changes. however, time.time() is not + # guaranteed to have sub-second precision. comparisons of + # "invalidation time" to "starttime" should perhaps use >= so that the + # state change can take place assuming no measurable time has passed, + # however this does not guarantee correct behavior here as if time + # continues to not pass, it will try to reconnect repeatedly until + # these timestamps diverge, so in that sense using > is safer. Per + # https://stackoverflow.com/a/1938096/34549, Windows time.time() may be + # within 16 milliseconds accuracy, so unit tests for connection + # invalidation need a sleep of at least this long between initial start + # time and invalidation for the logic below to work reliably. if self.connection is None: self.info.clear() self.__connect() elif ( self.__pool._recycle > -1 - and monotonic_time() - self.starttime > self.__pool._recycle + and time.time() - self.starttime > self.__pool._recycle ): self.__pool.logger.info( "Connection %r exceeded timeout; recycling", self.connection @@ -569,7 +577,7 @@ class _ConnectionRecord(object): # creator fails, this attribute stays None self.connection = None try: - self.starttime = monotonic_time() + self.starttime = time.time() connection = pool._invoke_creator(self) pool.logger.debug("Created new connection %r", connection) self.connection = connection |
