fix(ops): дрилл восстановления ждал БД по сокету и умирал на старте настоящего сервера
All checks were successful
CI Trade-In / changes (pull_request) Successful in 8s
CI Trade-In / backend-tests (pull_request) Has been skipped
CI Trade-In / browser-tests (pull_request) Has been skipped
CI / changes (pull_request) Successful in 10s
CI Trade-In / frontend-checks (pull_request) Has been skipped
CI / backend-tests (pull_request) Has been skipped
CI / frontend-tests (pull_request) Has been skipped
CI / openapi-codegen-check (pull_request) Has been skipped

`ops/restore-drill.sh` проверял готовность через `pg_isready -U postgres`, то
есть по unix-сокету. Образ postgres во время инициализации поднимает временный
сервер, который на сокете уже отвечает "accepting connections". Проба зеленела
посреди initdb, восстановление начиналось в этот временный сервер и погибало,
как только entrypoint гасил его ради настоящего:

    [12:26:22Z] Restoring dump into 'drill' (ON_ERROR_STOP=1 ...)
    FATAL:  terminating connection due to administrator command
    server closed the connection unexpectedly

Воспроизведено на проде 2026-08-21 на живом дампе `tradein-20260821-013001`:
падение через 6 секунд после старта. С `-h 127.0.0.1` тот же дамп проходит
восстановление и доходит до сборки индексов — временный сервер TCP не слушает,
поэтому по TCP проба зеленеет только на настоящем сервере.

Ровно та же проба и ровно по той же причине уже стоит в
`.forgejo/workflows/ci-tradein.yml:137-141`. Тот же дефект живёт и в
`.forgejo/workflows/deploy-tradein.yml:718-721` — там его чинят в PR #3011,
здесь не трогаю.

Refs #2203, #2989
This commit is contained in:
bot-backend 2026-08-21 15:42:36 +03:00
parent 4ae14055ec
commit b588278923

View file

@ -113,7 +113,15 @@ log "Container up, mapped to 127.0.0.1:${host_port} (only reachable while this d
log "Waiting for postgres to accept connections (timeout ${READY_TIMEOUT}s)..."
ready=0
for _ in $(seq 1 "$READY_TIMEOUT"); do
if docker exec "$CONTAINER" pg_isready -U postgres >/dev/null 2>&1; then
# -h 127.0.0.1 is load-bearing, NOT cosmetic. The postgres image runs a
# TEMPORARY server during initialisation, and that server already answers
# "accepting connections" on the unix socket. Probing the socket therefore
# goes green mid-init; the restore starts against the temporary server and
# dies with "FATAL: terminating connection due to administrator command"
# the moment the entrypoint shuts it down to start the real one. The
# temporary server does NOT listen on TCP, so a TCP probe only goes green
# on the real server. Same reasoning, same fix as ci-tradein.yml:137-141.
if docker exec "$CONTAINER" pg_isready -h 127.0.0.1 -U postgres >/dev/null 2>&1; then
ready=1
break
fi