From b996c3ad2d86d3f8c38eb3c8c7d49a89250c22df Mon Sep 17 00:00:00 2001 From: slayerjain Date: Wed, 8 Jul 2026 14:30:40 +0530 Subject: [PATCH] fix(echo-sql): probe TCP in the postgres healthcheck so the app can't 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 --- echo-sql/docker-compose.yml | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/echo-sql/docker-compose.yml b/echo-sql/docker-compose.yml index 1823f762..08389c62 100644 --- a/echo-sql/docker-compose.yml +++ b/echo-sql/docker-compose.yml @@ -30,11 +30,23 @@ services: - postgresDb healthcheck: - test: ["CMD-SHELL", "pg_isready -U postgres -d postgres"] + # Probe TCP (127.0.0.1:5432), NOT the default unix socket. During first-boot + # init the postgres entrypoint runs a TEMPORARY server that is reachable on + # the socket but not on TCP (listen_addresses is empty while init.sql runs; + # only afterwards does the real server bind 0.0.0.0:5432). A socket probe + # therefore reports "healthy" seconds before TCP accepts, so + # `depends_on: service_healthy` releases go-app while its TCP connect + # (host=postgresDb:5432, single attempt, no retry) is still refused and the + # app exits. The app talks to Postgres over TCP, so the gate must probe TCP. + test: ["CMD-SHELL", "pg_isready -h 127.0.0.1 -p 5432 -U postgres -d postgres"] interval: 5s timeout: 5s - retries: 5 - start_period: 30s + # Generous budget so the gate stays patient through a slow first-boot init on + # emulated amd64 (postgres:10.5 on Apple-silicon / colima CI runners), where + # the init window is many seconds wide. A fast native boot still flips healthy + # on the first successful probe — these only bound when we give up. + retries: 30 + start_period: 90s networks: babab: