Skip to content

fix(docker): don't let a stale postmaster.pid fake a PostgreSQL start - #25

Merged
akosidencio merged 1 commit into
devfrom
fix/docker-stale-postmaster-pid
Oct 29, 2026
Merged

akosidencio merged 1 commit into
devfrom
fix/docker-stale-postmaster-pid

Conversation

@akosidencio

Copy link
Copy Markdown
Member

Fixes the Docker image smoke tests failure on dev (re-created container on the same volume → pg_ctl: server started → psql: … No such file or directory).

Cause: docker rm -f leaves postmaster.pid in the volume. With the setpriv entrypoint, boots after the first run the same process sequence, so the new postmaster gets the same PID; if it starts within 2 s of the old lock's start time (CI re-creates in ~1.4 s), pg_ctl -w trusts the stale "ready" line and returns before PostgreSQL has a socket.

Fix: remove a lock whose PID is not a live postgres process in this container; then wait for pg_isready (≤ 60 s) before psql.

Test: docker-smoke.sh now plants exactly that lock (recorded postmaster PID, future start time, ready) and requires the next container to start. Locally: the pre-fix image fails this step with the CI error; the fixed image passes the full smoke test.

The Docker smoke job on dev fails at "re-created container on the same
volume": pg_ctl reports "server started" and psql then finds no socket.

`docker rm -f` (like any kill, OOM or node loss) leaves postmaster.pid in the
data volume. Since the entrypoint switched from `su` to `setpriv`, every boot
after the first runs the same process sequence, so the new postmaster gets
the same PID as the old one; when it also starts within two seconds of the
old lock's start time (CI re-creates in ~1.4 s), `pg_ctl -w` accepts the
stale file's "ready" line and returns before the server has finished crash
recovery or created its socket.

- Before starting, remove postmaster.pid when its PID is not a live postgres
  process in this container (nothing else runs PostgreSQL here).
- After pg_ctl, wait for pg_isready on the socket (up to 60 s, then fail
  with a pointer to the log) before running psql.

docker-smoke.sh now reproduces it deterministically: it records the
postmaster PID of a normal boot, kills the container, plants a lock with
that PID, a future start time and a "ready" status, and requires the next
container to start. The pre-fix image fails that step with the CI error;
the fixed image passes the whole smoke test.
@akosidencio
akosidencio merged commit 039ef6e into dev Oct 29, 2026
38 checks passed
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