From f3ecb9aa234a1e2be7fd4a43708ceff5ae5bcf8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=BB=D0=B5=D0=B1=20=D0=9F=D0=B0=D1=80=D0=B0=D0=BC?= =?UTF-8?q?=D0=BE=D0=BD=D0=BE=D0=B2?= Date: Fri, 16 Oct 2026 17:18:27 +0300 Subject: [PATCH] Wait for real volume readiness during initial bucket bootstrap --- src/bootstrap_storage.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/bootstrap_storage.py b/src/bootstrap_storage.py index 38cc43d..574a1d2 100644 --- a/src/bootstrap_storage.py +++ b/src/bootstrap_storage.py @@ -24,9 +24,19 @@ except ClientError as exc: if exc.response['Error']['Code'] not in ('NoSuchBucketPolicy','404'): raise else: raise RuntimeError('Unexpected bucket policy; inspect it before starting API') -try: - storage.client.head_object(Bucket=storage.bucket, Key=HEALTH_KEY) -except ClientError as exc: - if exc.response['Error']['Code'] not in ('404','NoSuchKey'): raise - storage.client.put_object(Bucket=storage.bucket, Key=HEALTH_KEY, Body=HEALTH_BYTES) +deadline=time.monotonic()+90 +while True: + try: + try: + storage.client.head_object(Bucket=storage.bucket, Key=HEALTH_KEY) + except ClientError as exc: + if exc.response['Error']['Code'] not in ('404','NoSuchKey'): raise + # Fixed, reserved key/content: retry after uncertain PUT is safe. + storage.client.put_object(Bucket=storage.bucket, Key=HEALTH_KEY, Body=HEALTH_BYTES) + storage.ready() + break + except (BotoCoreError,ClientError): + if time.monotonic()>=deadline: + raise RuntimeError('Storage volumes did not become ready within bootstrap deadline') from None + time.sleep(1) print('Private bucket ready; bootstrap is repeatable')