Skip to content

fix(echo-sql): probe TCP in postgres healthcheck (fixes macOS record flake at source)#237

Merged
slayerjain merged 1 commit into
mainfrom
fix/echo-sql-postgres-tcp-healthcheck
Jul 8, 2026
Merged

fix(echo-sql): probe TCP in postgres healthcheck (fixes macOS record flake at source)#237
slayerjain merged 1 commit into
mainfrom
fix/echo-sql-postgres-tcp-healthcheck

Conversation

@slayerjain

Copy link
Copy Markdown
Member

What

The echo-sql sample's postgres healthcheck probes the unix socket (pg_isready -U postgres). During the postgres image's first-boot init, a temporary socket-only server runs init.sql while TCP is not yet listening — so the socket probe reports healthy before 127.0.0.1:5432 accepts. depends_on: service_healthy then releases go-app, whose TCP connect (host=postgresDb:5432, single attempt, no retry) is refused → the app exits 1.

On emulated amd64 (postgres:10.5 on Apple-silicon / colima CI runners) the init window is wide, so this is a near-permanent race — it's the root cause of the flaky echo-sql macOS docker lane in keploy/keploy (see keploy/keploy#4335). Linux is latently exposed too; it just usually wins the race.

Fix

Probe TCP (pg_isready -h 127.0.0.1 -p 5432), matching how the app actually connects, so service_healthy only fires once the real server accepts TCP. Generous retries/start_period keep the gate patient through slow emulated init; a fast native boot still flips healthy on the first probe.

Fixing it in the sample (not just seddng it in one CI lane) fixes both CI lanes and every downstream user of this sample in one place.

Ref: keploy/keploy#4335

… race init

`pg_isready -U postgres` probes the unix socket, which is up during the
postgres first-boot init (a temporary socket-only server running init.sql)
while TCP is not yet listening. `depends_on: service_healthy` then releases
go-app, whose TCP connect (host=postgresDb:5432, single attempt, no retry) is
refused -> the app exits 1 and keploy record fails. The race is near-permanent
on emulated amd64 (postgres:10.5 on Apple-silicon/colima CI), where the init
window is wide.

Probe TCP (127.0.0.1:5432) instead, matching how the app connects, and give
the gate a generous retry/start_period budget for the slow emulated init. Fixes
the intermittent echo-sql failures on the macOS docker lane at the source, for
both CI lanes and anyone running the sample.

Ref: keploy/keploy#4335
Signed-off-by: slayerjain <shubhamkjain@outlook.com>
@slayerjain slayerjain force-pushed the fix/echo-sql-postgres-tcp-healthcheck branch from 087cde1 to b996c3a Compare July 8, 2026 09:01
@slayerjain slayerjain merged commit 9e18459 into main Jul 8, 2026
41 checks passed
slayerjain added a commit to keploy/keploy that referenced this pull request Jul 8, 2026
…ess (#4337)

The macOS echo-sql lane flakes because the sample compose healthcheck
(`pg_isready -U postgres`) probes the unix socket, which is up during postgres
first-boot init while TCP is not — so `depends_on: service_healthy` releases
the go-app before TCP accepts and its single-attempt, no-retry connect is
refused -> exit 1 -> record fails. Near-permanent on the emulated amd64
postgres:10.5 image on Apple-silicon runners.

The durable fix is upstream in keploy/samples-go#237 (TCP healthcheck). This
lane change hardens the CI orchestration so the lane is robust regardless:
- pre-start postgres and block on a TCP-ready barrier before keploy launches
  the app (also keeps the slow init out of the --record-timer window),
- idempotently normalize the compose healthcheck to a TCP probe as
  defense-in-depth (no-op once #237 is in the pinned samples-go; also covers
  the keploy-recreates-postgres path),
- a Docker-daemon readiness barrier for cold colima/Docker Desktop,
- replace bare `sleep` barriers with bounded condition-polls that dump app + DB
  diagnostics and fail loudly on timeout instead of hanging.

No retries/skips/sleeps-as-barriers in the product; root-cause only.

Fixes #4335

Signed-off-by: slayerjain <shubhamkjain@outlook.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