Skip to content

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

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

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

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. 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.

The regression test

scripts/test-pg-readiness-race.sh starts one postgres:16-alpine container and asks it both ways, back to back: the socket check, then the TCP check. It does so from before the container is up until the real server has answered twenty times in a row.

Outcome Meaning
the socket check says accepting and the TCP check does not the race window, counted
the TCP check says accepting and the socket check does not a failure: the TCP check passed early
the TCP check never reaches the real server a failure

Verification

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

pg-readiness-check:

Fact Result
Image postgres:16-alpine
Probes, each one socket check followed by one TCP check 35
Socket check answered accepting 21 times
TCP check answered accepting 20 times
Moments in the race window: socket yes, TCP no 1
Moments with TCP yes and socket no 0
First TCP accept about 2 s after the start
Result PASS: the TCP check never answered before the real server was up

The test did what it is for. It caught the race window in a real PostgreSQL container, once in 35 probes, and it showed that the TCP form does not answer in that window. One probe is thin evidence for how often the window is hit: the run was a single one.

The rest of the run, with the two smoke tests on the TCP check: release-tooling-validation passed on the first attempt.

Not covered

  • One run of the test on one image tag. The window was caught once; its frequency is not known.
  • The fix was not tried against the old form in the same job, to make the job fail. The test compares the two forms probe by probe instead, which shows the window without depending on a job failing.
  • The smoke tests could still meet the window in another form, if the real server restarts after it first answered. 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 and
asks it both ways, back to back, from before it is up until the real
server answers. It fails when the socket check answers accepting while
the TCP check does not. The new CI job pg-readiness-check runs it. It
also counts the moments of the race window, which the old form of the
check was exposed to.

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-23T06:28:44.784811Z 519810a 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 519810a46d

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

[ "$s" = 1 ] && socket_sees=$((socket_sees + 1))
[ "$t" = 1 ] && tcp_sees=$((tcp_sees + 1))
if [ "$s" = 1 ] && [ "$t" = 0 ]; then race_moments=$((race_moments + 1)); fi
if [ "$t" = 1 ] && [ "$s" = 0 ]; then tcp_first=$((tcp_first + 1)); fi

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Recheck the socket before treating TCP success as premature

If PostgreSQL finishes starting between the socket probe on line 35 and the TCP probe on line 36, the first probe legitimately fails and the second succeeds. This condition nevertheless increments tcp_first, causing the script to exit with failure even after twenty successful TCP checks. Consequently, the new pg-readiness-check job in .github/workflows/ci.yml can intermittently fail healthy CI runs. A simulated normal startup with only the first probe failing reproduces this outcome. Recheck the socket after TCP succeeds, or use an independent startup-state assertion, rather than interpreting sequential observations as simultaneous.

Useful? React with 👍 / 👎.

@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: 1
AI judgment: NEEDS DISCUSSION · Evidence: COMPLETE · Authority: advisory
Evidence complete · 2/2 changed files accounted for

Key issues

  • [HIGH] Regression test fails spuriously when the real server starts between its socket and TCP probes (scripts/test-pg-readiness-race.sh) 🔮

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


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

echo "first TCP accept after about ${first_tcp_s}s"
echo "moments with socket=yes and TCP=no (the race window): $race_moments"
echo "moments with TCP=yes and socket=no: $tcp_first"
if [ "$tcp_first" -ne 0 ]; then echo "FAIL: the TCP check passed where the socket check did not"; exit 1; 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.

[HIGH] Regression test fails spuriously when the real server starts between its socket and TCP probes

Each loop iteration runs the socket check first and the TCP check immediately after, then fails the whole run if any single iteration recorded t=1 && s=0 (tcp_first, enforced at the if [ "$tcp_first" -ne 0 ] ... exit 1 line). That condition also occurs at the normal, expected startup transition: if the real server becomes accepting in the gap between the socket probe and the TCP probe of the same iteration, s=0 and t=1 are recorded and the script exits 1, failing the new pg-readiness-check job even though the fix is working exactly as intended. With two docker exec invocations per iteration (~50-100 ms each), the socket-to-TCP gap covers a sizable fraction of each cycle, so the per-run flake probability is plausibly tens of percent - i.e., the patch introduces a new flaky CI job in a PR whose whole purpose is removing CI flakiness. The assertion is also structurally unable to detect the regression it targets: if the temporary server ever listened on TCP it would listen on the socket too (s=1, t=1), so tcp_first would stay 0; the only realistic producer of t=1 && s=0 is benign timing skew. Suggested fix: re-probe before declaring failure. E.g. on t=1 && s=0, sleep 0.2 and re-run the socket check; count tcp_first only if the re-check also fails. A genuine TCP-only temporary server would still fail the socket re-check, while the normal transition would not, eliminating the spurious exit.

@Alajmah

Alajmah commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Both reviews on this pull request found the same defect in scripts/test-pg-readiness-race.sh, and they were right. The test failed when the real server came up between its socket probe and its TCP probe: the socket check then says no, the TCP check says yes, and the test counted that as a premature TCP answer. That is a normal start.

The fix is on a new branch, because a branch cannot be updated here. The successor keeps the workflow change byte for byte and replaces the criterion of the test with one that holds: once the TCP check has answered accepting, it has to answer accepting in every later probe. A check that had answered against the temporary server stops answering when that server stops.

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

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