Files
mtusi2026lab3/evidence/replicas/lb-errors.md
T
ricoromaandClaude Opus 5.5 de93056eab docs: add replicas-lb evidence and report
Evidence from 4e0cc4e: stand ports, limits and per-service env,
X-Instance-Id distribution and scaling, LB-generated errors,
test-persistence through the LB, test-failover for each replica in stop
and kill modes, stop-one refusals, test runs and bench self-checks.
REPORT.md gains the LB architecture, timeout chain, limits, criteria
rows and defence answers. Coverage exclusions for restart now point to
the lab 3 persistence evidence; stale lab 2 pointers go to
KNOWN_ISSUES.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-10 18:31:18 +03:00

102 lines
5.9 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.
# Ответы самого балансировщика: нет готовых реплик
| | |
|---|---|
| Спеки | `load-balancing` «Ошибки балансировщика в формате контракта» — «Нет готовых реплик»; «Проверка готовности реплик» — «Остановленная реплика исключена», «Вернувшаяся реплика включена»; `api-conventions` «X-Instance-Id на каждом ответе» (ответы LB — исключение по контракту) |
| Change | `replicas-lb`, задача 6.1 |
| Дата | 2026-10-10 15:21:39–15:22:08 UTC |
| Commit | `4e0cc4e` |
| Стенд | `make run_docker`: проект `mtusi-lab3`, HAProxy на `127.0.0.1:8080`, `api` × 2 |
| Хост | Docker Desktop 29.8.1, macOS arm64; ВМ Docker: 12 CPU, 7,7 GiB RAM; ноутбук от батареи |
Обе реплики остановлены напрямую `docker stop` (не `stop-one.sh`: он
останавливает ровно одну). Через 3 с:
```text
$ docker stop $(docker compose ps -q api)
0a93eeb192b4
47a14cfd6cd7
$ make lb_stats
svname addr status check_status scur stot econ wretr wredis hrsp_5xx
api-1 172.30.0.5:8080 DOWN L4TOUT 0 1077 0 0 9 0
api-2 172.30.0.4:8080 DOWN L4TOUT 0 963 0 0 8 0
BACKEND - DOWN - 0 2034 2 0 18 6
free slots: 6
$ curl -si http://127.0.0.1:8080/health/ready
HTTP/1.1 503 Service Unavailable
x-request-id: lb-AC1E0001F2F86ACA580708AA0007
content-length: 119
content-type: application/json
{"error":{"code":"unavailable","message":"No API replica is available","request_id":"lb-AC1E0001F2F86ACA580708AA0007"}}
$ curl -si -X POST -H "Content-Type: application/json" -d "{}" http://127.0.0.1:8080/api/v1/users
HTTP/1.1 503 Service Unavailable
x-request-id: lb-AC1E0001F2FC6ACA580708AB0007
content-length: 119
content-type: application/json
{"error":{"code":"unavailable","message":"No API replica is available","request_id":"lb-AC1E0001F2FC6ACA580708AB0007"}}
# проверка формы ответа LB (stdlib)
status 503 | keys ['error'] ['code', 'message', 'request_id'] | code unavailable | request_id == X-Request-Id: True | X-Instance-Id: None
$ docker compose ps haproxy # ещё через 14 с
mtusi-lab3-haproxy-1 Up 14 minutes (unhealthy)
```
- Ответ создал HAProxy (`http-error status 503 … lf-string` в
`defaults`): тело — формат ошибки контракта без лишних полей, `code`
`unavailable`, `request_id` совпадает с `X-Request-Id`.
`X-Instance-Id` нет — контракт это разрешает для ответов LB.
- `POST /api/v1/users` тоже получил 503 от LB и до API не дошёл:
повторять его LB не стал бы и при живых репликах (запрос уже ушёл
бы на реплику; `retry-on conn-failure`).
- Healthcheck контейнера LB (`/lb/ready`, 503 при `nbsrv(api) < 1`)
перевёл `haproxy` в `unhealthy`: «через LB нельзя обслужить запрос».
## Восстановление
```text
$ make replicas
Container mtusi-lab3-api-2 Healthy
Container mtusi-lab3-api-1 Healthy
$ docker compose ps # через 4 с
mtusi-lab3-api-1 Up 5 seconds (healthy)
mtusi-lab3-api-2 Up 5 seconds (healthy)
mtusi-lab3-haproxy-1 Up 14 minutes (healthy)
$ curl -s -o /dev/null -w "%{http_code}" http://127.0.0.1:8080/health/ready
200
```
## Журнал LB за окно
```text
Server api/api-2 is DOWN, reason: Layer4 timeout, check duration: 505ms. 1 active and 0 backup servers left. 0 sessions active, 0 requeued, 0 remaining in queue.
Server api/api-1 is DOWN, reason: Layer4 timeout, check duration: 501ms. 0 active and 0 backup servers left. 0 sessions active, 0 requeued, 0 remaining in queue.
backend api has no server available!
172.30.0.1:62200 [10/Oct/2026:15:21:43.715] entry api/<NOSRV> 0/-1/-1/-1/0 503 0 - - SC-- 1/1/0/0/0 0/0 "GET /health/ready HTTP/1.1"
172.30.0.1:62204 [10/Oct/2026:15:21:43.724] entry api/<NOSRV> 0/-1/-1/-1/0 503 0 - - SC-- 1/1/0/0/0 0/0 "POST /api/v1/users HTTP/1.1"
172.30.0.1:62218 [10/Oct/2026:15:21:43.801] entry api/<NOSRV> 0/-1/-1/-1/0 503 0 - - SC-- 1/1/0/0/0 0/0 "GET /health/ready HTTP/1.1"
Server api/api-1 was DOWN and now enters maintenance (DNS NX status).
Server api/api-2 was DOWN and now enters maintenance (DNS NX status).
api/api-1: IP changed from '(none)' to '172.30.0.5' by 'docker/dns'.
api/api-2: IP changed from '(none)' to '172.30.0.4' by 'DNS cache'.
Server api/api-1 ('api') is DOWN/READY (resolves again).
Server api/api-1 administratively READY thanks to valid DNS answer.
Server api/api-2 ('api') is DOWN/READY (resolves again).
Server api/api-2 administratively READY thanks to valid DNS answer.
Server api/api-2 is UP, reason: Layer7 check passed, code: 200, check duration: 2ms. 1 active and 0 backup servers online. 0 sessions requeued, 0 total in queue.
Server api/api-1 is UP, reason: Layer7 check passed, code: 200, check duration: 5ms. 2 active and 0 backup servers online. 0 sessions requeued, 0 total in queue.
```
- Остановленные реплики LB исключил по проверкам (`Layer4 timeout`:
адрес остановленного контейнера пропадает, соединение ограничено
`timeout connect` 500 мс), затем по DNS (`DNS NX`) — слоты ушли в
обслуживание.
- Вернувшиеся реплики получили прежние адреса, начали в `DOWN`
(`init-state down`) и вошли в распределение после проверки
`/health/ready`, без перезапуска LB.
- `SC--` — LB сам отказал в соединении с сервером: готовых реплик нет.