Files
mtusi2026lab2/evidence/storage/pool-timeout.md
T
ricoromaandClaude Opus 5.5 8a5d2b8c8a docs: add postgres-storage evidence
- migrations from zero, schema and rerun on 2d0a7c8
- restart hook, database outage, pool timeout, postgres port
- make test_isolated mechanics: failure, stop, Ctrl+C, kill -9, keep db
- align REPORT.md numbers with the new evidence

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-01 16:27:58 +03:00

49 lines
2.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Исчерпание пула соединений: 503 по таймауту ожидания, а не бесконечная очередь
| | |
|---|---|
| Спек | `data-storage` «Соединения исчерпаны» |
| Change | `postgres-storage`, задача 5.4 |
| Дата | 2026-10-01 13:24 UTC |
| Commit | `2d0a7c8` |
| Стенд | сервис в console (`driver.py start`: `make upgrade`, затем `uv run python -m src`) на `127.0.0.1:18080`, Postgres из compose |
| Переопределено окружением | `DATABASE__POOL_SIZE=1`, `DATABASE__MAX_OVERFLOW=0`, `DATABASE__POOL_TIMEOUT_SECONDS=1` |
| Хост | Docker Desktop 29.8.1, macOS arm64; ВМ Docker: 12 CPU, 7 GiB RAM; лимиты контейнерам не задавались |
| Клиент | разовый stdlib-скрипт: два запроса одновременно, второй через 0,3 с после первого; id сокращены |
## Подготовка
| Запрос | Статус | Результат |
|---|---|---|
| `POST /users` (alice) | 201 | id `edaa3f10…` |
## `docker compose pause postgres`, два запроса одновременно
| Запрос | Статус | Результат | Время |
|---|---|---|---|
| `GET /users/me` №1 (держит единственное соединение) | 503 | `unavailable` | 8,00 с |
| `GET /users/me` №2 (через 0,3 с, ждёт пул) | 503 | `unavailable` | 1,01 с |
## `docker compose unpause postgres`
| Запрос | Статус | Результат | Время |
|---|---|---|---|
| `GET /users/me` (alice) | 200 | id `edaa3f10…` | 0,04 с |
## Журнал сервиса
Записи `Database is unavailable` за время сценария:
```json
{"timestamp": "2026-10-01T13:24:20.411310Z", "event": "Database is unavailable", "error_type": "TimeoutError", "error": "QueuePool limit of size 1 overflow 0 reached, connection timed out, timeout 1.00 (Background on this error at: https://sqlalche.me/e/21/3o7r)", "level": "warning"}
{"timestamp": "2026-10-01T13:24:27.104944Z", "event": "Database is unavailable", "error_type": "TimeoutError", "error": "", "level": "warning"}
```
## Вывод
- Второй запрос не дождался соединения за `pool_timeout_seconds=1`:
`sqlalchemy.exc.TimeoutError` и 503 через 1 с.
- Первый держал соединение с замёрзшим сервером: 503 через срок
запроса 6 с плюс 2 с на обрыв соединения.
- После разморозки сервис отвечает без рестарта.