Skip to content

Commit aefa428

Browse files
committed
fix: Cap the sync Redis feature store upsert retry loop at 10 attempts
1 parent 1f4d0f7 commit aefa428

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

ldclient/impl/integrations/redis/redis_feature_store.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
except ImportError:
1616
pass
1717

18+
# Cap the WATCH-retry loop so a hot-contended key can't starve upsert_internal forever; matches the LaunchDarkly Go Redis stores.
19+
_MAX_UPSERT_RETRIES = 10
20+
1821

1922
class _RedisFeatureStoreCore(DiagnosticDescription, FeatureStoreCore):
2023
def __init__(self, url, prefix, redis_opts: Dict[str, Any]):
@@ -82,7 +85,7 @@ def upsert_internal(self, kind, item):
8285
key = item['key']
8386
item_json = json.dumps(item)
8487

85-
while True:
88+
for _ in range(_MAX_UPSERT_RETRIES):
8689
pipeline = r.pipeline()
8790
pipeline.watch(base_key)
8891
old = self.get_internal(kind, key)
@@ -111,6 +114,8 @@ def upsert_internal(self, kind, item):
111114
continue
112115
return item
113116

117+
raise RuntimeError("failed to update key %s in '%s' after %d attempts" % (key, kind.namespace, _MAX_UPSERT_RETRIES))
118+
114119
def initialized_internal(self):
115120
r = redis.Redis(connection_pool=self._pool)
116121
return r.exists(self._init_key)

0 commit comments

Comments
 (0)