From f8c81878cbe2a2bdc2cc443ba63e6d35dabfe5ff Mon Sep 17 00:00:00 2001 From: roman Date: Tue, 13 Oct 2026 16:45:25 +0300 Subject: [PATCH] fix: run the fault stand postgres under an init process Co-Authored-By: Claude Opus 5.5 --- student-tests/failures.compose.yml | 10 ++++++++++ student-tests/fault_hook.py | 3 +++ 2 files changed, 13 insertions(+) diff --git a/student-tests/failures.compose.yml b/student-tests/failures.compose.yml index 11c2675f..fd9687b9 100644 --- a/student-tests/failures.compose.yml +++ b/student-tests/failures.compose.yml @@ -12,8 +12,18 @@ # проверка — сессия в pg_stat_database базы. Иначе раз в 5 с она попадала # бы в счётчик теста «Соединения пула не переоткрываются» (действие hook # db-sessions). +# +# У PostgreSQL — init (tini) с PID 1, postmaster — его потомок. fault_hook.py +# fill-connections отвязывает psql в фоне sh, запущенного docker compose exec; +# после clear-connections они становятся сиротами пространства PID. С init их +# молча подбирает он, а не postmaster: тот считал их «untracked child process» +# и выход с кодом 2 — аварией (все процессы завершены, recovery, сброс +# статистики). Только на стенде отказов: на рабочем стенде и в bench/ фоновых +# процессов в контейнере PostgreSQL нет (design change fix-known-issues, +# решение 11). Правило docker.md «сервер — PID 1» касается образа API. services: postgres: + init: true ports: !reset [] healthcheck: test: ["CMD-SHELL", "pg_isready -h 127.0.0.1 -U \"$$POSTGRES_USER\" -d postgres"] diff --git a/student-tests/fault_hook.py b/student-tests/fault_hook.py index 9d14e766..2b272bd4 100755 --- a/student-tests/fault_hook.py +++ b/student-tests/fault_hook.py @@ -118,6 +118,9 @@ SELECT sessions FROM pg_stat_database WHERE datname = current_database(); # срока: слот, освободившийся после обрыва соединения API, сразу занимает # снова psql, а не переподключение пула. Лишние попытки получают отказ и # выходят. Сессии — через сокет ([local]), пользователь контейнера. +# После CLEAR_FILL_SH фоновые psql — сироты пространства PID: их подбирает +# init стенда отказов (init: true у postgres в failures.compose.yml), а не +# postmaster, для которого выход чужого потомка с кодом 2 — авария FILL_PID = "/tmp/fault-fill.pid" FILL_SH = f"""\ echo $$ > {FILL_PID}