There is a race condition between shrinking the pool and closing an
expired connection which might result in attempting to pop from the
empty _pool deque. Add a check to prevent that.
The bug is not serious as it doesn't compromise the pool working but it causes
noise in the logging.
Close #1001
``psycopg_pool`` release notes
==============================
+psycopg_pool 3.2.5 (unreleased)
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+- Fix spurious warning logging on pool shrinking (:ticket:`#1001`).
+
+
Current release
---------------
self._nconns_min = len(self._pool)
# If the pool can shrink and connections were unused, drop one
- if self._nconns > self._min_size and nconns_min > 0:
+ if self._nconns > self._min_size and nconns_min > 0 and self._pool:
to_close = self._pool.popleft()
self._nconns -= 1
self._nconns_min -= 1
self._nconns_min = len(self._pool)
# If the pool can shrink and connections were unused, drop one
- if self._nconns > self._min_size and nconns_min > 0:
+ if self._nconns > self._min_size and nconns_min > 0 and self._pool:
to_close = self._pool.popleft()
self._nconns -= 1
self._nconns_min -= 1