Skip to content

fix(ci): every PostgreSQL readiness gate in CI waits over TCP (#501) - #509

Merged
Alajmah merged 2 commits into
masterfrom
fix/pg-readiness-over-tcp-v6
Nov 23, 2026
Merged

Alajmah merged 2 commits into
masterfrom
fix/pg-readiness-over-tcp-v6

Conversation

@Alajmah

@Alajmah Alajmah commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Status

The fix of #501 as the review refined it, rebuilt on current master so the squash carries exactly the three intended files and nothing else (a branch built on the pre-#504 master would have shown, and a squash would have applied, a revert of the executor's Node 24 Dockerfile).

What it changes

With #506 carried in, all three PostgreSQL readiness gates in CI go over TCP: the service health-cmd of docker-build-app, and the wait loops and fail-closed checks of publish-release-images and release-tooling-validation. scripts/check-pg-readiness-tcp.sh is a static gate proving no socket-form pg_isready remains; the pg-readiness-check job runs it after the race test.

Verification

Two commits cherry-picked from #506 (ce3a275) and #507 (001c48c) onto master cd23a11. Manual CI run on this branch: all 17 jobs passed, publish-release-images skipped on a manual run by design. The race test caught the socket form's window once again (2 of the probes, socket yes / TCP no; the TCP form never stopped answering). The static gate passed. The two smoke tests ran on the TCP check.

Supersedes

#506 and #507 (both closed as superseded; #507's head 001c48c is one of the two cherry-picked commits, so its content is here in full).

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:44:10.136673Z cb54b67 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: 4
AI judgment: APPROVE · Evidence: COMPLETE · Authority: advisory
Evidence complete · 3/3 changed files accounted for

Other findings (4)

  • [low] Race test's fixed 120s wall-clock cap can abort after TCP already answered
  • [medium] TCP accept does not imply PostgreSQL readiness — bare-TCP gates can pass while the server is still starting up ⚠️ unverified
  • [low] localhost TCP probes may resolve to ::1 and hit the wrong listener ⚠️ unverified
  • [low] Race test covers one configuration; 'every gate' is verified by inspection only ⚠️ unverified

🔮 Devil's Advocate (2 turns): 3 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)

  • [MEDIUM] TCP accept does not imply PostgreSQL readiness — bare-TCP gates can pass while the server is still starting up

    The postmaster binds its listen socket early in startup and ACKs connections before recovery/initdb completes, replying to startup packets with 'the database system is starting up'. Worse, with a published container port, Docker's userland proxy accepts TCP immediately regardless of whether anything inside the container is listening (accept-then-RST — which is very likely the 'flicker' the race test is hunting). If any gate converted from pg_isready/--health-cmd to a bare TCP connect (nc -z, /dev/tcp) with no protocol handshake afterwards, it can succeed seconds before Postgres can actually serve queries, making downstream steps (migrations, test suites) flakily fail with 'the database system is starting up'. The race test validates port stability, not readiness semantics, so it would not catch this. Needs verification: does every gate follow the TCP open with a real protocol-level check (pg_isready -h, psql SELECT 1) or at least a documented reason bare TCP suffices?

  • [LOW] localhost TCP probes may resolve to ::1 and hit the wrong listener

    If the new TCP waits target 'localhost', name resolution can return ::1 while Postgres listens only on 127.0.0.1 (default listen_addresses='localhost' behavior varies by image), or worse, connect to an unrelated ::1 listener. Different tools on the runner (nc vs bash /dev/tcp vs curl) have different IPv6 fallback behavior, so some gates could silently probe the wrong endpoint. Cheap to eliminate: probe 127.0.0.1 explicitly in all gates and the race script.

  • [LOW] Race test covers one configuration; 'every gate' is verified by inspection only

    The new race script exercises a single PG_IMAGE/entrypoint/timing profile. The PR's claim is that every readiness gate waits over TCP, but gates spread across multiple workflow files with different images, health-cmd remnants, or timeout budgets are only verified by eyeballing the diff, not by the race harness. A parameterized matrix run (or at least a grep-based assertion that no gate still uses the old socket/pg_isready-only pattern without TCP) would close the gap between 'one path is tested' and 'every gate is fixed'.

now=$(date +%s)
if [ "$t" = 1 ] && [ -z "$first_tcp_at" ]; then first_tcp_at=$now; first_tcp_s=$((now - start)); fi
if [ -n "$first_tcp_at" ] && [ $((now - first_tcp_at)) -ge "$WATCH" ]; then break; fi
if [ $((now - start)) -gt 120 ]; then echo "FAIL: $IMAGE did not answer over TCP within 120 s"; exit 2; fi

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] Race test's fixed 120s wall-clock cap can abort after TCP already answered

In scripts/test-pg-readiness-race.sh the loop evaluates the WATCH-based break (now - first_tcp_at >= WATCH) before the hard timeout check (now - start > 120). If the first TCP accept lands after ~105s (slow runner, custom PG_IMAGE, WATCH_SECONDS raised), the WATCH break would need now >= first_accept+15 which exceeds 120s, so the timeout branch fires first and the script exits 2 with 'FAIL: ... did not answer over TCP within 120 s' even though the TCP check had already started answering and the actual assertion (zero tcp_flickers) was on track to pass. This turns a rare-but-possible slow startup into a spurious red guard job with a misleading message. Fix: only apply the 120s budget while waiting for the first accept, e.g. change the check to [ -z "$first_tcp_at" ] && [ $((now - start)) -gt 120 ] && { ...; exit 2; }, or start the clock before docker run. Low likelihood on standard GitHub runners (postgres initdb is usually well under 60s), hence P3.

@Alajmah
Alajmah merged commit 0a0257d into master Nov 23, 2026
41 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