Skip to content

fix(start-server): stop and exit when a setup step fails - #2489

Closed
breken-ai wants to merge 1 commit into
supabase:developfrom
breken-ai:fix/run-server-abort-on-failure
Closed

breken-ai wants to merge 1 commit into
supabase:developfrom
breken-ai:fix/run-server-abort-on-failure

Conversation

@breken-ai

Copy link
Copy Markdown

What kind of change does this PR introduce?

Bug fix (developer tooling: nix run .#start-server, nix/tools/run-server.sh.in).

What is the current behavior?

Every setup failure path in run-server.sh.in calls 'stop_postgres' 1. There are 9 of these: the startup wait, role creation, --migration-file, init scripts, the supabase_admin password, the pgbouncer and stat schema files, migrations, and the final schema. stop_postgres ignores its argument and never exits. In --daemonize mode it also doesn't stop anything; it only prints "PostgreSQL is running in daemon mode...". So when an init script or migration fails, the script:

  • keeps running the remaining init scripts and migrations against a half-initialized database,
  • then restarts the server, and
  • exits 0.

The error is only visible in scrollback. Anyone using start-server to test a new migration can miss that it failed.

What is the new behavior?

A new abort_setup helper stops the setup server with pg_ctl stop -D "$DATDIR" -m fast (in either mode, since setup always runs a daemonized server) and exits 1. All 9 'stop_postgres' 1 calls now use it. The Ctrl-C trap and the normal shutdown/restart flow are unchanged.

Additional context

How I tested it: I rendered the .sh.in with its @...@ placeholders pointed at a stock postgres:17 container, using a minimal config and a migrations dir. The init scripts were 00-ok.sql, 01-broken.sql (select 1/0) and 02-after.sql, plus one migration. I ran it as start-postgres-server 17 --daemonize --datdir /tmp/dat. PGOPTIONS cleared session_preload_libraries, because the stock image has no supautils.

exit server afterwards tables created
develop, broken init script 0 running after_failure, migrated, ok1 (kept going after the error)
this branch, broken init script 1 stopped none past the failure; prints Error: database setup failed, stopping PostgreSQL
this branch, all scripts OK 0 running after_failure, migrated, ok1 (same as develop)

bash -n passes. The .sh.in isn't covered by shfmt, and I kept its existing 4-space style.

This PR was prepared by an AI agent (Claude) working for breken-ai. I reproduced the bug and checked the fix as described above, and I'm happy to change anything.

Every failed setup step called `'stop_postgres' 1`, which neither exits
nor stops a daemonized server: stop_postgres ignores its argument and,
in --daemonize mode, only prints a message. A failing init script or
migration therefore let the script carry on with the remaining scripts,
restart the server and exit 0 with a partially initialized database.

Add abort_setup, which stops the setup server with pg_ctl and exits 1,
and use it for every failure path.
@breken-ai
breken-ai requested review from a team as code owners September 26, 2026 04:32
@imor

imor commented Sep 27, 2026

Copy link
Copy Markdown
Contributor

Closing as this is 100% AI generated.

@imor imor closed this Sep 27, 2026
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.

2 participants