Не доверять кэшу сессий после рестарта API

Флаг очистки кэша жил только в памяти процесса. Сценарий: logout при
недоступном Valkey (отзыв записан в PostgreSQL, tombstone нет) -> рестарт
API -> Valkey вернулся. Новый процесс читал устаревшую положительную запись,
и отозванный токен получал 200 на /users/me и 201 на отправку сообщения
до истечения TTL записи (до 60 s).

Теперь процесс стартует с включённым флагом и выполняет FLUSHDB перед
первым использованием кэша. Добавлен регрессионный тест
test_logout_during_outage_then_api_restart, evidence и отчёт обновлены.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-10-03 10:31:12 +03:00
co-authored by Claude Opus 5.5
parent 8e97518120
commit ed012ba09d
9 changed files with 126 additions and 81 deletions
+9 -1
View File
@@ -38,7 +38,7 @@ PASS: forged token still 401 without Valkey
PASS: anonymous still 401 without Valkey
PASS: logout works without Valkey
PASS: token revoked during outage -> 401
PASS: bounded latency during outage (max 0.27s)
PASS: bounded latency during outage (max 0.26s)
PASS: token revoked during outage stays 401 after Valkey returns (stale cache flushed)
PASS: live session works after recovery
@@ -55,6 +55,14 @@ PASS: bounded latency during outage (max 0.26s)
PASS: token revoked during outage stays 401 after Valkey returns (stale cache flushed)
PASS: live session works after recovery
== logout while Valkey hangs, API restart, Valkey returns
PASS: token cached before outage
PASS: positive cache entry exists in Valkey
PASS: logout committed in PostgreSQL, tombstone not written
PASS: API restarted while Valkey is unreachable
PASS: revoked token -> 401 after API restart (got 401)
PASS: revoked token cannot send messages (got 401)
== PostgreSQL stop: limited 503, anonymous is never trusted
PASS: token cached before outage
PASS: write -> 503 unavailable with request id (3.01s)