Skip to content

fix(ci): wait for PostgreSQL over TCP in the release smoke tests (#501) - #506

Closed
Alajmah wants to merge 1 commit into
masterfrom
fix/pg-readiness-over-tcp-v3
Closed

Alajmah wants to merge 1 commit into
masterfrom
fix/pg-readiness-over-tcp-v3

Conversation

@Alajmah

@Alajmah Alajmah commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Status

The fix of #501, as the review asked: a small change and an independent regression test. This supersedes #505, whose regression test had a defect that two reviews found. Created for review. The merge needs the maintainer's approval.

What failed

The smoke tests of publish-release-images and release-tooling-validation waited for PostgreSQL with pg_isready over the Unix socket. The postgres image runs a temporary server during its own setup that listens on the Unix socket only. So the wait could pass against that server, and the fail-closed check after it could land in the restart window and fail the job. Seen once, on #499: PG not ready, after a step of five seconds.

The change

Both jobs now call pg_isready with -h 127.0.0.1. The temporary server does not listen on TCP, so the check answers only when the real server is up.

File Change
.github/workflows/ci.yml, job publish-release-images the loop and the fail-closed check use -h 127.0.0.1
.github/workflows/ci.yml, job release-tooling-validation the same
scripts/test-pg-readiness-race.sh new: the regression test
.github/workflows/ci.yml, job pg-readiness-check new: runs the test

The --health-cmd of the service container in docker-build-app is left as it is. A Docker health check is asked again until it passes, so it does not depend on one answer.

What was wrong in #505, and what the test asserts now

#505's test failed when the TCP check answered accepting in a probe whose socket check, run just before, had not. That can happen in a normal start: the real server comes up between the two probes. The reviews on #505 were right, and that criterion is gone.

The test now asserts one thing: once the TCP check has answered accepting, it answers accepting in every later probe. It keeps probing for fifteen seconds after the first accept. A check that had answered against a temporary server stops answering when that server stops, and that fails the test.

How often the socket form answered accepting while the TCP form did not is printed and not judged. It depends on timing. A socket "no" beside a TCP "yes" is not counted as anything.

Verification

Manual CI run on this branch, commit ce3a275: https://github.com/Octo-Lex/GitWire/actions/runs/45130729269. All 17 jobs passed, the new one included; publish-release-images is skipped on a manual run by design.

pg-readiness-check, one postgres:16-alpine container:

Fact Result
Probes, each one socket check followed by one TCP check 134
Socket check answered accepting 123 times
TCP check answered accepting 122 times
The socket check stopped answering after it had answered 1 time. This is the failure of #501, seen in a real container
The TCP check stopped answering after it had answered 0 times
Probes with socket yes and TCP no, the race window 1
First TCP accept about 1 s after the start, then 15 s of probing
Result PASS: once the TCP check answered accepting, it kept answering

The logic was also checked offline against four recorded probe sequences: the run seen in CI, a real server starting between the two probes, a start without any race window, and a check that had answered against a temporary TCP server. The first three pass and the last fails.

The two smoke tests on the TCP check: release-tooling-validation passed on the first attempt.

Not covered

  • Two runs of the test in all, on one image tag. The window was caught once in each. How often it is hit is not known.
  • The test does not make the old job fail. It shows the window of the old form beside the new form, probe by probe.
  • A restart of the real server after it first answered would break the assertion. Nothing observed points to it.

The smoke tests of publish-release-images and
release-tooling-validation waited for PostgreSQL with pg_isready over
the Unix socket. The postgres image runs a temporary server during its
own setup that listens on the Unix socket only, so the wait could pass
against it and the fail-closed check after it could then land in the
restart window and fail the job with "PG not ready" (#501).

Both jobs now call pg_isready with -h 127.0.0.1. The temporary server
does not listen on TCP, so the check answers only when the real server
is up.

scripts/test-pg-readiness-race.sh starts one postgres container, asks
it both ways, back to back, from before it is up, and keeps asking for
fifteen seconds after the TCP check first answered. It asserts one
thing: once the TCP check has answered accepting, it answers accepting
in every later probe. A check that had answered against a temporary
server would stop answering when that server stops. How often the
socket form answered accepting while the TCP form did not is reported
and not judged, because it depends on timing; a socket "no" beside a
TCP "yes" means nothing, since the real server can start between the
two probes. The new CI job pg-readiness-check runs the test.

Signed-off-by: Alajmah <55954113+Alajmah@users.noreply.github.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-23T07:31:24.281110Z ce3a275 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@gitwire-hq gitwire-hq Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 AI Code Review — ✅ Approved

Confidence: high · Findings: 2
AI judgment: APPROVE · Evidence: COMPLETE · Authority: advisory
Evidence complete · 2/2 changed files accounted for

Other findings (2)

  • [medium] Same socket-vs-TCP race likely remains in the docker-build-app service health-cmd ⚠️ unverified
  • [low] Regression test conflates docker exec failures with server flickers

🔮 Devil's Advocate (2 turns): 2 upheld


GitWire AI Review Gate (bundle-driven v2) · Structured schema · Scope-validated · Devil's Advocate · AI recommendation — maintainers and repository policy retain authority

Finding details (not annotatable inline)

  • [MEDIUM] Same socket-vs-TCP race likely remains in the docker-build-app service health-cmd (.github/workflows/ci.yml)

    The PR fixes the two explicit wait loops, but the description confirms the postgres service container's --health-cmd in docker-build-app is deliberately left on the old form. The stated rationale ('a Docker health check is asked again until it passes, so it does not depend on one answer') does not actually cover the failure mode: the very first passing probe marks the service healthy and the job's steps start immediately. If that first pass lands against the temporary init-only server, the app starts inside the restart window — exactly the #499/#501 flake this PR fixes elsewhere. Docker's retry logic only helps before the first success, not after it. Suggest applying the same -h 127.0.0.1 change to the --health-cmd (or verifying it already uses TCP) so the fix covers every readiness check in the workflow. Lowered to P2 since that line is not visible in the diff and the impact there depends on whether the app retries its first DB connection.

while :; do
probes=$((probes + 1))
s=0; docker exec "$NAME" pg_isready -U gitwire -d gitops_hub >/dev/null 2>&1 && s=1
t=0; docker exec "$NAME" pg_isready -h 127.0.0.1 -U gitwire -d gitops_hub >/dev/null 2>&1 && t=1

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[LOW] Regression test conflates docker exec failures with server flickers

In the probe loop, any non-zero result from docker exec ... pg_isready is counted as 'not accepting'. After the first TCP accept, a transient docker-level error (daemon hiccup, exec failure with exit 125/126/127) would be indistinguishable from the server stopping: it increments tcp_flickers and exits 1, failing CI even though PostgreSQL behaved correctly and the assertion's premise was never violated. Suggest distinguishing docker/invocation errors from pg_isready results (0 = accepting, 1 = rejecting, 2 = no response), e.g. by only counting flickers when pg_isready itself reported 'no response' rather than an exec error, or by re-probing once before recording a flicker. Unlikely on a fresh GitHub runner, hence P3.

@Alajmah

Alajmah commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

The review of 2026-11-23 accepted the approach of this pull request and asked for one more gate: the service health-cmd of docker-build-app also used a socket-form pg_isready, which can pass against the postgres image's temporary setup server.

That third gate is closed on a new branch, built on this pull request's head: the health-cmd uses -h 127.0.0.1, and a static gate (scripts/check-pg-readiness-tcp.sh, run by the pg-readiness-check job) proves that no socket-form pg_isready remains anywhere in the workflow. It fails on this pull request's workflow and passes on the successor's.

This pull request is closed as superseded, unmerged. Its branch and its record stay.

@Alajmah Alajmah closed this Nov 23, 2026
Alajmah added a commit that referenced this pull request Nov 23, 2026
…509)

* fix(ci): wait for PostgreSQL over TCP in the release smoke tests

The smoke tests of publish-release-images and
release-tooling-validation waited for PostgreSQL with pg_isready over
the Unix socket. The postgres image runs a temporary server during its
own setup that listens on the Unix socket only, so the wait could pass
against it and the fail-closed check after it could then land in the
restart window and fail the job with "PG not ready" (#501).

Both jobs now call pg_isready with -h 127.0.0.1. The temporary server
does not listen on TCP, so the check answers only when the real server
is up.

scripts/test-pg-readiness-race.sh starts one postgres container, asks
it both ways, back to back, from before it is up, and keeps asking for
fifteen seconds after the TCP check first answered. It asserts one
thing: once the TCP check has answered accepting, it answers accepting
in every later probe. A check that had answered against a temporary
server would stop answering when that server stops. How often the
socket form answered accepting while the TCP form did not is reported
and not judged, because it depends on timing; a socket "no" beside a
TCP "yes" means nothing, since the real server can start between the
two probes. The new CI job pg-readiness-check runs the test.

Signed-off-by: Alajmah <55954113+Alajmah@users.noreply.github.com>

* fix(ci): the docker-build-app health check also waits for PostgreSQL over TCP

Third gate of #501, after #506. The service container of docker-build-app
used --health-cmd with pg_isready over the Unix socket, which can pass
against the postgres image's temporary setup server. A health check is
asked again until it passes, so the service is eventually reported
healthy; but a first pass against the temporary server can mark the
service healthy while the real server is still coming up, and the job's
steps start on that.

The health-cmd now uses -h 127.0.0.1, like the wait loop and the
fail-closed check of the two smoke jobs since #506.

scripts/check-pg-readiness-tcp.sh is a static gate: every pg_isready in
the workflow has to use -h 127.0.0.1, in the health-cmd, in the two
smoke jobs, and in this job's own step names. It fails on the master
workflow and passes here, and the pg-readiness-check job runs it after
the race test.

Signed-off-by: Alajmah <55954113+Alajmah@users.noreply.github.com>

---------

Signed-off-by: Alajmah <55954113+Alajmah@users.noreply.github.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