summary refs log tree commit diff
path: root/synapse
diff options
context:
space:
mode:
authorRichard van der Hoff <richard@matrix.org>2017-11-27 11:56:57 +0000
committerRichard van der Hoff <richard@matrix.org>2017-11-27 12:00:07 +0000
commit63ccaa58736ca098a0d52000bdbc2df589b8cdaa (patch)
treeac040865b3771edb5c071e4527048f140ad5c112 /synapse
parentMerge pull request #2701 from matrix-org/rav/one_mediarepo_to_rule_them_all (diff)
downloadsynapse-63ccaa58736ca098a0d52000bdbc2df589b8cdaa.tar.xz
Avoid retrying forever on IntegrityError
Diffstat (limited to 'synapse')
-rw-r--r--synapse/storage/_base.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/synapse/storage/_base.py b/synapse/storage/_base.py
index e6eefdd6fe..662c30187d 100644
--- a/synapse/storage/_base.py
+++ b/synapse/storage/_base.py
@@ -495,6 +495,7 @@ class SQLBaseStore(object):
             Deferred(bool): True if a new entry was created, False if an
                 existing one was updated.
         """
+        attempts = 0
         while True:
             try:
                 result = yield self.runInteraction(
@@ -504,6 +505,12 @@ class SQLBaseStore(object):
                 )
                 defer.returnValue(result)
             except self.database_engine.module.IntegrityError as e:
+                attempts += 1
+                if attempts >= 5:
+                    # don't retry forever, because things other than races
+                    # can cause IntegrityErrors
+                    raise
+
                 # presumably we raced with another transaction: let's retry.
                 logger.warn(
                     "IntegrityError when upserting into %s; retrying: %s",