From 882f496e0a1093239a26cdbf29c9af5c5fe9977c Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Tue, 11 Feb 2020 22:00:24 +0100 Subject: [PATCH 1/1] nominatim.py: also catch deadlocks on final wait --- nominatim/nominatim.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/nominatim/nominatim.py b/nominatim/nominatim.py index 848846ae..ac6d23ff 100755 --- a/nominatim/nominatim.py +++ b/nominatim/nominatim.py @@ -123,8 +123,20 @@ class DBConnection(object): def wait(self): """ Block until any pending operation is done. """ - wait_select(self.conn) - self.current_query = None + while True: + try: + wait_select(self.conn) + self.current_query = None + return + except psycopg2.extensions.TransactionRollbackError as e: + if e.pgcode == '40P01': + log.info("Deadlock detected (params = {}), retry." + .format(self.current_params)) + self.cursor.execute(self.current_query, self.current_params) + else: + raise + except psycopg2.errors.DeadlockDetected: + self.cursor.execute(self.current_query, self.current_params) def perform(self, sql, args=None): """ Send SQL query to the server. Returns immediately without @@ -158,6 +170,8 @@ class DBConnection(object): self.cursor.execute(self.current_query, self.current_params) else: raise + except psycopg2.errors.DeadlockDetected: + self.cursor.execute(self.current_query, self.current_params) return False -- 2.39.5