Skip to content

Commit e176600

Browse files
committed
estuary-cdk: add basic retry logic for config encryption requests
When rotating OAuth2 tokens, a task can end up with a broken config if the token exchange succeeds, invalidates all previous tokens, then the connector fails to emit a `configUpdate` event. To guard against this failure mode a little, very basic retry logic was added for when the config encryption service experiences transient failures. I haven't observed any config encryption failures in the wild, but it's feasible something could happen causing Google Cloud Run to temporarily be down.
1 parent 634487e commit e176600

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

estuary-cdk/estuary_cdk/capture/base_capture_connector.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,30 @@ async def _encrypt_config(
177177
"schema": config.model_json_schema(),
178178
}
179179

180-
encrypted_config = await self.request(log, ENCRYPTION_URL, "POST", json=body, _with_token = False)
180+
# Retry for up to an hour if the encryption service is unavailable. Tasks can end up with broken configs
181+
# if the updated config isn't encrypted & emitted in a configUpdate event. Retrying transient errors
182+
# helps avoid being left with broken configs due to temporary encryption service outages.
183+
max_retries = 20
184+
retry_count = 0
185+
backoff_seconds = 300
186+
187+
while True:
188+
try:
189+
encrypted_config = await self.request(log, ENCRYPTION_URL, "POST", json=body, _with_token=False)
190+
break
191+
except HTTPError as err:
192+
if err.code >= 500 and retry_count < max_retries:
193+
retry_count += 1
194+
195+
log.warning(f"Request failed (attempt {retry_count} of {max_retries}). Retrying in {backoff_seconds} seconds.", {
196+
"error code": err.code,
197+
})
198+
await asyncio.sleep(backoff_seconds)
199+
else:
200+
log.error("Failed to encrypt config.", {
201+
"error code": err.code,
202+
})
203+
raise
181204

182205
return json.loads(encrypted_config.decode('utf-8'))
183206

0 commit comments

Comments
 (0)