From a1736bccae3204207559d13f0a1124c4367bf973 Mon Sep 17 00:00:00 2001 From: "Gavin M. Roy" Date: Tue, 7 Jul 2020 16:21:01 -0400 Subject: [PATCH] Actually wait while the first in reconnects --- sprockets_postgres.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/sprockets_postgres.py b/sprockets_postgres.py index 4895fb1..5f11e2d 100644 --- a/sprockets_postgres.py +++ b/sprockets_postgres.py @@ -344,14 +344,17 @@ class ApplicationMixin: message = str(err) if isinstance(err, psycopg2.OperationalError) and _attempt == 1: LOGGER.critical('Disconnected from Postgres: %s', err) + retry = True if not self._postgres_reconnect.locked(): async with self._postgres_reconnect: - if await self._postgres_connect(): - async with self.postgres_connector( - on_error, on_duration, timeout, - _attempt + 1) as connector: - yield connector - return + retry = await self._postgres_connect() + if retry: + await self._postgres_connected.wait() + async with self.postgres_connector( + on_error, on_duration, timeout, + _attempt + 1) as connector: + yield connector + return message = 'disconnected' exc = on_error('postgres_connector', ConnectionException(message)) if exc: