mirror of
https://mau.dev/maunium/synapse.git
synced 2024-12-15 02:33:51 +01:00
Merge pull request #2713 from matrix-org/rav/no_upsert_forever
Avoid retrying forever on IntegrityError
This commit is contained in:
commit
84b31a3e7a
1 changed files with 7 additions and 0 deletions
|
@ -495,6 +495,7 @@ class SQLBaseStore(object):
|
||||||
Deferred(bool): True if a new entry was created, False if an
|
Deferred(bool): True if a new entry was created, False if an
|
||||||
existing one was updated.
|
existing one was updated.
|
||||||
"""
|
"""
|
||||||
|
attempts = 0
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
result = yield self.runInteraction(
|
result = yield self.runInteraction(
|
||||||
|
@ -504,6 +505,12 @@ class SQLBaseStore(object):
|
||||||
)
|
)
|
||||||
defer.returnValue(result)
|
defer.returnValue(result)
|
||||||
except self.database_engine.module.IntegrityError as e:
|
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.
|
# presumably we raced with another transaction: let's retry.
|
||||||
logger.warn(
|
logger.warn(
|
||||||
"IntegrityError when upserting into %s; retrying: %s",
|
"IntegrityError when upserting into %s; retrying: %s",
|
||||||
|
|
Loading…
Reference in a new issue