Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: procrastinate-org/procrastinate
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 161c857e0f39de01ce8b82845a1b9e4540c3275b
Choose a base ref
..
head repository: procrastinate-org/procrastinate
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: d634e386cb888fe92800cf006cbf0a23493d2a57
Choose a head ref
Showing with 18 additions and 2 deletions.
  1. +10 −2 procrastinate/aiopg_connector.py
  2. +8 −0 procrastinate/psycopg2_connector.py
12 changes: 10 additions & 2 deletions procrastinate/aiopg_connector.py
Original file line number Diff line number Diff line change
@@ -42,9 +42,17 @@ async def wrapped(*args, **kwargs):

def wrap_query_exceptions(coro: CoroutineFunction) -> CoroutineFunction:
"""
Detect psycopg2 OperationalError's with a "server closed the connection
unexpectedly" message and retry a number of times.
Detect aiopg OperationalError's with a "server closed the connection unexpectedly"
message and retry a number of times.
This is to handle the case where the database connection (obtained from the pool)
was actually closed by the server. In this case, aiopg raises an OperationalError
with a "server closed the connection unexpectedly" message (and no pgcode) when the
connection is used for issuing a query. What we do is retry when an OperationalError
is raised, and until max_tries is reached.
max_tries is set to the max pool size + 1 (maxsize + 1) to handle the case where all
the connections we have in the pool were closed by the server.
"""

@functools.wraps(coro)
8 changes: 8 additions & 0 deletions procrastinate/psycopg2_connector.py
Original file line number Diff line number Diff line change
@@ -39,6 +39,14 @@ def wrap_query_exceptions(func: Callable) -> Callable:
Detect psycopg2 InterfaceError's with a "connection already closed" message and
retry a number of times.
This is to handle the case where the database connection (obtained from the pool)
was actually closed by the server. In this case, pyscopg2 raises an InterfaceError
with a "connection already closed" message (and no pgcode) when the connection is
used for issuing a query. What we do is retry when an InterfaceError is raised, and
until max_tries is reached.
max_tries is set to the max pool size + 1 (maxconn + 1) to handle the case where
all the connections we have in the pool were closed by the server.
"""

@functools.wraps(func)