]> git.openstreetmap.org Git - nominatim.git/commitdiff
nominatim.py: also catch deadlocks on final wait
authorSarah Hoffmann <lonvia@denofr.de>
Tue, 11 Feb 2020 21:00:24 +0000 (22:00 +0100)
committerSarah Hoffmann <lonvia@denofr.de>
Tue, 11 Feb 2020 21:16:17 +0000 (22:16 +0100)
nominatim/nominatim.py

index 848846ae45123b28b69b53513c378d2ab0435231..ac6d23ffb070c41744e178b6c0e14124d2ef5f9f 100755 (executable)
@@ -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