Retry to get a connection when an OperationalError is raised

If there are no connection available in the pool, psycopg2 tries to create a
new connection but it may raise an OperationalError if the server close it.

Closes #13475
(grafted from cecbc1736f2d0fdd8a77c1dcdfe81e23cf99f451)

--HG--
branch : 7.0
This commit is contained in:
Cédric Krier
2024-08-26 09:33:58 +02:00
parent 56b85baa8f
commit 8a8f9f966d
@@ -259,7 +259,7 @@ class Database(DatabaseInterface):
for count in range(retry, -1, -1):
try:
conn = self._connpool.getconn()
except PoolError:
except (PoolError, DatabaseOperationalError):
if count and not self._connpool.closed:
logger.info('waiting a connection')
time.sleep(1)