Skip to content

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

Open
Alajmah wants to merge 2 commits into
masterfrom
fix/pg-readiness-over-tcp-v5
Open

Alajmah wants to merge 2 commits into
masterfrom
fix/pg-readiness-over-tcp-v5

Conversation

@Alajmah

@Alajmah Alajmah commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Status

The fix of #501, as the review of 2026-11-23 refined it: the third PostgreSQL readiness gate, in docker-build-app, now also waits over TCP, plus a static gate that proves no socket-form pg_isready remains anywhere in the workflow. Built on #506's head (ce3a275); the workflow change of #506 is carried unchanged. Created for review. The merge needs the maintainer's approval.

What failed

The service container of docker-build-app used --health-cmd 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 health check could pass against it. A health check is asked again until it passes, but a first pass against the temporary server can still mark the service healthy while the real server is still coming up.

The change

File Change
.github/workflows/ci.yml, service container of docker-build-app --health-cmd uses -h 127.0.0.1
scripts/check-pg-readiness-tcp.sh new: the static gate
.github/workflows/ci.yml, job pg-readiness-check a second step runs the static gate

With this branch, all three readiness gates go over TCP: the service health-cmd, and the wait loops and fail-closed checks of the two smoke jobs (from #506).

The static gate

scripts/check-pg-readiness-tcp.sh lists every line of the workflow that mentions pg_isready and fails when any of them is an invocation without -h 127.0.0.1. Comment lines and YAML name/uses lines are skipped, so the gate's own step name does not trip it. It takes a workflow path as an argument, which is how its negative proof works.

Run against Result
this branch's workflow PASS
a scratch copy with the health-cmd reverted to the socket form FAIL (exit 1)

Verification

Manual CI run on this branch, commit 001c48c: https://github.com/Octo-Lex/GitWire/actions/runs/45190244460. All 17 jobs passed; publish-release-images is skipped on a manual run by design.

pg-readiness-check, both steps:

Step Result
The race test (postgres:16-alpine) 145 probes. The socket form answered accepting and then stopped answering once — the failure of #501, seen again in a real container. The TCP form, after its first accept, never stopped answering. PASS
The static gate PASS: every pg_isready in the workflow uses -h 127.0.0.1

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

Not covered

  • Three runs of the race test in all, on one image tag. How often the window is hit is not known.
  • The static gate checks this workflow only. Other workflows name no PostgreSQL readiness check.

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>
…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>
@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-23T14:12:52.534285Z 001c48c 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 — 💬 Needs discussion

Confidence: medium · Findings: 5
AI judgment: NEEDS DISCUSSION · Evidence: COMPLETE · Authority: advisory
Evidence complete · 3/3 changed files accounted for

Key issues

  • [HIGH] TCP health check may target the wrong host in the containerized job topology 🔍 ⚠️ unverified

Other findings (4)

  • [low] Static gate passes silently if all real pg_isready invocations are removed
  • [medium] Readiness wait loop appears unbounded ⚠️ unverified
  • [medium] pg_isready binary availability in the target image was not verified ⚠️ unverified
  • [medium] Gate wiring and scan scope unverified — it may be dead code or trivially outflanked ⚠️ unverified

🔮 Devil's Advocate (3 turns): 4 missed risks found · 1 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)

  • [HIGH] TCP health check may target the wrong host in the containerized job topology

    The PR's core change makes the docker-build-app health check wait for PostgreSQL over TCP, but the review never examined where pg_isready runs. If the check executes inside the app container, '-h localhost' / '-h 127.0.0.1' points at the app container's own loopback, not a PostgreSQL container on the compose network — the check would loop forever or fail unless the containers share a network namespace or the correct service hostname (e.g., 'db') is used. This is the single most common way 'switch to TCP' fixes are wrong, and it went unexamined.

  • [MEDIUM] Readiness wait loop appears unbounded

    Wait loops added to CI jobs ('until pg_isready ...; do sleep N; done') with no retry cap or timeout cause opaque multi-hour hangs and wasted runner minutes when PostgreSQL never comes up (bad credentials, wrong port, DB image not started). The review critiqued the static gate's logic but said nothing about bounding the runtime loop the gate exists to police.

  • [MEDIUM] pg_isready binary availability in the target image was not verified

    Slim/alpine runtime images frequently omit postgresql-client, so a pg_isready-based health check fails at runtime with 'command not found' even though the static gate passes. Nothing in the review confirmed the client package is installed in whatever image or runner environment actually executes the check.

  • [MEDIUM] Gate wiring and scan scope unverified — it may be dead code or trivially outflanked

    The review critiqued the gate's internal logic but did not confirm (a) that any workflow actually invokes scripts/check-pg-readiness-tcp.sh — an unwired gate is pure dead code — or (b) that it scans all places pg_isready can live. Socket-form invocations can sit in repo shell scripts (entrypoints, embedded healthcheck scripts) rather than workflow YAML, and simply moving the check out of the YAML defeats the gate entirely. A one-line PR audit of where the script is called and what paths it greps was missing from a review that otherwise fixated on an edge case inside the script itself.

echo "FAIL: no pg_isready found in $WF"
exit 1
fi
BAD=$(printf '%s\n' "$LINES" | grep -v -- "-h 127.0.0.1" | grep -vE "^[0-9]+:[[:space:]]*#" | grep -vE "^[0-9]+:[[:space:]]*(- )?(name|uses):" || true)

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] Static gate passes silently if all real pg_isready invocations are removed

check-pg-readiness-tcp.sh only fails when a pg_isready line is a socket-form invocation. The "no pg_isready found" guard on line 14-18 only triggers when there are zero mentions of any kind (including comments). So if a future edit deletes every actual readiness check but leaves any comment or a step name that mentions pg_isready (e.g. the comment "The smoke tests of the release jobs wait for PostgreSQL with pg_isready."), LINES is non-empty, BAD is empty after the comment/name/uses filters, and the gate prints PASS with no real check present. The protection the gate exists to enforce can therefore be removed without the gate noticing. Suggested fix: after computing BAD, also assert that at least one mention survives the comment/name/uses exclusions (i.e., count non-excluded pg_isready lines) and fail with a distinct message when that count is zero, so both "socket-form remnant" and "no checks at all" are failures.

This branch has not been deployed

No deployments
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