From 046e257f9032f7e10c61de846cf1074322068e3f Mon Sep 17 00:00:00 2001 From: Alexey Bodanyuk <144894236+wfa22@users.noreply.github.com> Date: Sun, 25 Oct 2026 15:04:58 +0300 Subject: [PATCH] =?UTF-8?q?fix:=20=D0=BE=D0=B4=D0=BD=D0=B0=20=D0=BF=D0=BE?= =?UTF-8?q?=D0=B2=D1=82=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=20=D0=BF=D0=BE=D0=BF?= =?UTF-8?q?=D1=8B=D1=82=D0=BA=D0=B0=20S3=20=D0=B2=20=D1=82=D0=BE=D0=BC=20?= =?UTF-8?q?=D0=B6=D0=B5=20=D0=B4=D0=B5=D0=B4=D0=BB=D0=B0=D0=B9=D0=BD=D0=B5?= =?UTF-8?q?=20(=D0=BC=D1=91=D1=80=D1=82=D0=B2=D1=8B=D0=B5=20keep-alive=20?= =?UTF-8?q?=D0=BF=D0=BE=D1=81=D0=BB=D0=B5=20=D1=80=D0=B5=D1=81=D1=82=D0=B0?= =?UTF-8?q?=D1=80=D1=82=D0=B0=20S3)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Найдено прогоном из чистого clone: после stop/start S3 первое скачивание получало 503 на соединении из пула к старому процессу. Все операции идемпотентны по ключу. Тест TTL при рестарте: 30 с (рестарт Valkey + API с проверкой S3 дольше 12 с). Co-Authored-By: Claude Opus 5.5 --- src/messenger/storage.py | 9 ++++++--- student-tests/test_sessions.py | 3 ++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/messenger/storage.py b/src/messenger/storage.py index 67f39d0..a8d7e6d 100644 --- a/src/messenger/storage.py +++ b/src/messenger/storage.py @@ -7,8 +7,11 @@ * Deadlines: botocore connect/read timeouts AND an asyncio deadline around every call, so a paused or unreachable S3 costs at most S3_TIMEOUT_SECONDS, then 503 `unavailable`. Unlike a libpq query (db.py), an aiohttp request can be cancelled safely, so the call is cancelled. -* No retries inside botocore (max_attempts=1): the request handler decides; an upload is not - retried behind the client's back (contract: a retry may create another object). +* ONE retry inside botocore (total_max_attempts=2), within the same asyncio deadline: after S3 + restarts, pooled keep-alive connections to the old process are dead and the first request on + such a connection fails although S3 is up again (found by test_s3_outage_..._stop on a clean + clone). Every call here is idempotent PER KEY (PUT of the same bytes to the same server-chosen + key, GET, HEAD, DELETE), so repeating it cannot create a second attachment. * Checksums: Content-MD5 is sent with every PUT, so S3 rejects bytes damaged on the way. botocore's newer default (aws-chunked CRC32 trailers) is switched off ("when_required"): plain, widely supported S3 requests. @@ -65,7 +68,7 @@ class Storage: self._config = AioConfig( connect_timeout=settings.s3_connect_timeout_seconds, read_timeout=settings.s3_timeout_seconds, - retries={"total_max_attempts": 1, "mode": "standard"}, + retries={"total_max_attempts": 2, "mode": "standard"}, s3={"addressing_style": "path"}, signature_version="s3v4", request_checksum_calculation="when_required", diff --git a/student-tests/test_sessions.py b/student-tests/test_sessions.py index 8cbda00..40d793b 100644 --- a/student-tests/test_sessions.py +++ b/student-tests/test_sessions.py @@ -38,7 +38,8 @@ def test_short_ttl_expires(api, store): def test_restart_does_not_extend_ttl(api): - with api_with_env(SESSION_TTL_SECONDS="12"): + # 30 s: a restart of Valkey + both API replicas (readiness now also waits for S3) takes ~12-15 s. + with api_with_env(SESSION_TTL_SECONDS="30"): actor = api.register("ttlrestart") session = login_session(api, actor) restart_services("valkey", "api")