fix: improve connection pool idle and max age checks to allow disabling

This commit is contained in:
serversdwn
2026-02-19 01:25:01 +00:00
parent b62e84f8b3
commit af5ecc1a92
2 changed files with 406 additions and 3 deletions

View File

@@ -454,11 +454,11 @@ class ConnectionPool:
"""Check whether a cached connection is still usable."""
now = time.time()
# Age / idle checks
if now - conn.last_used_at > self._idle_ttl:
# Age / idle checks (value of -1 disables the check)
if self._idle_ttl >= 0 and now - conn.last_used_at > self._idle_ttl:
logger.debug(f"Connection {conn.device_key} idle too long ({now - conn.last_used_at:.0f}s > {self._idle_ttl}s)")
return False
if now - conn.created_at > self._max_age:
if self._max_age >= 0 and now - conn.created_at > self._max_age:
logger.debug(f"Connection {conn.device_key} too old ({now - conn.created_at:.0f}s > {self._max_age}s)")
return False