From add56d818caf2a13a5649f32568de60402e11c42 Mon Sep 17 00:00:00 2001 From: Johannes Millan Date: Tue, 28 Apr 2026 15:46:14 +0200 Subject: [PATCH] fix(infra): close db-startup race in supersync e2e stack MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit pg_isready -U supersync without -d returned OK as soon as postgres accepted connections to the default database, but during first-run initdb the server briefly bounced while POSTGRES_DB was created. supersync's prisma db push then race-failed with P1001. - Healthcheck now runs psql -d supersync_db -c 'SELECT 1' so it only passes once the app's db is queryable. - Dockerfile.test entrypoint retries prisma db push up to 15x before giving up — defense in depth if anything else ever races. --- docker-compose.yaml | 17 ++++++++++++++--- packages/super-sync-server/Dockerfile.test | 9 +++++++-- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/docker-compose.yaml b/docker-compose.yaml index b890578dc0..b098eec15f 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -11,11 +11,22 @@ services: - '55432:5432' volumes: - db_data:/var/lib/postgresql/data + # Gate on supersync_db existing AND accepting queries from the app user. + # Plain `pg_isready -U supersync` returns OK as soon as postgres accepts + # connections to the default `postgres` database — but during first-run + # initdb the server briefly bounces while POSTGRES_DB is created, so + # supersync's `prisma db push` race-fails with P1001. Querying + # supersync_db directly closes that window. healthcheck: - test: ['CMD-SHELL', 'pg_isready -U supersync'] - interval: 5s + test: + [ + 'CMD-SHELL', + 'pg_isready -U supersync -d supersync_db && psql -U supersync -d supersync_db -c "SELECT 1" > /dev/null 2>&1', + ] + interval: 3s timeout: 5s - retries: 5 + retries: 20 + start_period: 10s # SuperSync server for E2E testing # Start with: docker compose up -d supersync diff --git a/packages/super-sync-server/Dockerfile.test b/packages/super-sync-server/Dockerfile.test index 4cc0f24791..0dd54fd3f5 100644 --- a/packages/super-sync-server/Dockerfile.test +++ b/packages/super-sync-server/Dockerfile.test @@ -50,5 +50,10 @@ ENV TEST_MODE_CONFIRM=yes-i-understand-the-risks ENV CORS_ORIGINS=* ENV JWT_SECRET=e2e-test-secret-minimum-32-chars-long-for-security -# Push schema to DB and start server -CMD sh -c "npx prisma db push && node dist/src/index.js" +# Push schema to DB and start server. +# Retry `prisma db push` for up to ~30s on transient connection failures +# (postgres can briefly bounce during first-run initdb even after the db's +# healthcheck passes). Without this, the container exits on first P1001 +# and depends on docker's restart policy to recover, which can't be relied +# on across compose invocations. +CMD sh -c "for i in $(seq 1 15); do npx prisma db push && break; echo \"prisma db push failed (attempt $i/15), retrying in 2s...\"; sleep 2; done && node dist/src/index.js"