Skip to content

fix(http-postgres): the db's healthcheck counts no failed probe while Postgres starts - #250

Draft
slayerjain wants to merge 1 commit into
mainfrom
train/fix/http-postgres-db-start-period
Draft

slayerjain wants to merge 1 commit into
mainfrom
train/fix/http-postgres-db-start-period

Conversation

@slayerjain

Copy link
Copy Markdown
Member

What

http-postgres/docker-compose.yml: the db healthcheck gets start_period: 10m.

Why

On a fresh volume Postgres runs initdb before it listens on TCP. The healthcheck gives that about 10 s: 5 probes, 2 s apart, with no start period. On a loaded host, initdb can take longer. The db then goes unhealthy while it is still starting, and api fails with it, because it waits on depends_on: service_healthy.

keploy's T2 CI lane (keploy/enterprise, CI-AR-01, t2-flow-e2e) runs this compose file twice per compose cycle, for keploy record and for the CI checkout's keploy test. A slow initdb there turns the lane red when nothing is wrong. The lane's rule is to wait on progress, not on a clock. The healthcheck was the one wait in it that a clock bounded.

Behaviour

  • Failed probes during start_period do not count. The first probe that passes marks the db healthy. A db that starts is waited on until it answers, and no longer.
  • A db that exits still ends the wait at once: dependency failed to start: container ... exited (N).
  • A db that runs but never answers is unhealthy after start_period plus 5 more probes.

Checked on docker 29.7.2 with compose 5.5.1. A dependency that exits fails docker compose up within seconds. A dependency that turns healthy only on its 12th probe, after the old limit of 5, still lets its dependent start.

The lane is pinned to this branch's commit for its proof. It moves to the merge commit once this merges.

… Postgres starts

On a fresh volume Postgres runs initdb before it listens on TCP. On a
loaded host that can outlast the healthcheck's 5 probes 2 s apart (about
10 s, no start_period): the db went unhealthy while it was still starting,
and api, which waits for it with depends_on: service_healthy, failed with
it. keploy's T2 lane (keploy/enterprise CI-AR-01) runs this compose file
on its record and its CI checkout, and a slow initdb there was a red with
nothing wrong.

start_period: 10m: no failed probe counts while the db starts, and the
first that passes marks it healthy, so a db that starts is waited on until
it answers and no longer. One that exits still ends the wait at once
(compose: "dependency failed to start: container ... exited"), and one
that runs and never answers is unhealthy after start_period and 5 more
probes. Checked on docker 29.7.2 and compose 5.5.1: a dependency that
exits fails compose up in seconds, and one healthy only on its 12th probe,
past the old 5, lets its dependent start.

Signed-off-by: slayerjain <shubhamkjain@outlook.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant