Repository navigation
Description
Summary
GlitchTip tale/tale#343 (PostgresError: the database system is shutting down, imported as task TALE-406) belongs to the database-restart class. #3506 and #3548 (0.5.62 and later) made that class routine for requests, jobs, pg-boss and /events. One path was left out: boot.
A backend process that starts while the app database is restarting fails the migrator's first query (runBootMigrations → pg_advisory_lock) with the restart's own refusal. That refusal is 57P03 the database system is shutting down, … is starting up, or a refused connection. main().catch then reports it at error level (tale.lane: boot) and exits 1. The orchestrator restarts the process with a growing backoff, and every attempt reports again.
This contradicts the documented contract in docs/en/self-hosted/configuration/observability-config.md: "A database restart is not reported as an error". It also delays recovery: Docker's restart backoff grows to a minute. And it mints error-level GlitchTip issues titled like a driver defect, which the task importer turns into triage cards.
Which path can send this title today (main a703a9598)
PostgresError is the error class of postgres.js, and only the platform backend uses postgres.js. 57P03 the database system is shutting down is how PostgreSQL refuses a new connection while it shuts down. On 0.5.62 and later, three paths can still send that exact title. I reproduced each one locally (see below).
| Path | Level | Tags and location | Disposition |
|---|---|---|---|
/events outage watch (realtime/sse.ts): a poll is still refused as "shutting down" when the outage reaches 60 s |
warning | tale.lane: events-poll, transaction GET /events, extra.outageMs ≥ 60000 |
Expected (#3506): one report per process for an outage longer than a minute. "Shutting down" at the 60 s mark means the database's stop itself took about a minute. That is close to compose's 60 s SIGKILL deadline (stop_grace_period), so it is an Ops signal, not a code defect. |
Boot (main.ts → runBootMigrations) |
error | tale.lane: boot, no transaction, process exit 1 |
This issue, fixed by the linked PR. |
Boot, knowledge database (main.ts → ensureDefaultCorpusSchema, worker and all roles) |
error | tale.lane: boot, no transaction. The process keeps running, and its breadcrumbs show default corpus bootstrap failed |
Same class, not fixed by #4031. It needs a design decision (the BM25 scan is skipped too): #4035. |
Requests, jobs and /events on releases before 0.5.62 |
error | the route as the transaction, or job frames | Duplicate of #3273, fixed by #3506 and #3548. |
GlitchTip groups issues by title and location (apps/event_ingest/process_event.py: generate_hash(title, culprit, …), where culprit is the transaction or else the crash frame). So each row is a separate GlitchTip issue with the same title. #343's level, tale.lane tag and release decide which row it is. The import carries only the title and the value, so those fields still have to be read in GlitchTip. The event's breadcrumbs also name the step: [backend] fatal startup error for the migrations, [backend] default corpus bootstrap failed for the knowledge database, /events: database unavailable for the stream.
Local evidence
Setup: an isolated PostgreSQL 16 on loopback, the backend started with the platform image's own command line (ROLE=all), and SENTRY_DSN pointing at a local fake ingest. A no-egress preload refused any non-loopback connection. There was no contact with production. The rig, logs and events are attached to TALE-406.
- S1: fast restart (SIGINT, as
docker compose restart dbdoes), about 50 s down, under load.- 0 events, and the process stayed up.
- Requests answered 503
DATABASE_UNAVAILABLEwithRetry-After: 5. Four of them were refused with exactly57P03 the database system is shutting down, and one blocked mid-query got 57P01. /pingstayed 200 throughout./readyanswered 503, then 200 3 s after the database returned.- The hint stream stayed open and delivered again afterwards, and jobs resumed.
- S2: a 75 s shutdown phase. Existing sessions got 57P01, and every new connection was refused with 57P03.
- Exactly 1 event:
PostgresError: the database system is shutting down, level warning,tale.lane: events-poll, transactionGET /events,outageMs: 65044.
- Exactly 1 event:
- S3: a process started inside the shutdown phase.
- 1 error event:
PostgresError: the database system is shutting down,tale.lane: boot, then exit 1 within 6 s. - Started with the database down instead:
Error: connect ECONNREFUSED …,tale.lane: boot, exit 1.
- 1 error event:
- S4: backend SIGTERM in the same instant as the database stop (the host-reboot case). Exit 0 in under 1 s, and 0 events.
- S6: does a retried transaction get applied twice? Over 6 fast shutdowns under 40 concurrent writers, 161 transactions were cut, 46 of them at
COMMIT(43 got 57P01, 3 got ECONNRESET). 0 of them committed anyway, so rerunning a whole transaction after a fast shutdown (transactSerializable→withRetry) did not apply it twice.
Expected
A restart shorter than the outage threshold is routine at boot too. The process waits for the database, logs warnings, and boots once the database is back. A database that is still unreachable after that fails the start and is reported, as today.
Not in scope (follow-ups that need a decision)
- Knowledge-database boot steps. A knowledge-db restart at boot is reported at error level and skips the BM25 scan. This is now bug(platform): a knowledge-database restart at backend boot is reported as an error and skips the BM25 index check #4035, reproduced locally.
- Title of the long-outage warning.
/eventsuses the raw driver error as the event's title, so one condition mints a GlitchTip issue per message: "shutting down", "starting up",ECONNREFUSED, and so on. A stable title, with the driver error kept as context, would group it once. - Crash-mode stops. An ambiguous commit after a SIGKILL or OOM stop was not tested. A fast shutdown produced none. A crashed server process under an open transaction crashes the backend process itself, through postgres.js's null-socket write: bug(platform): a Postgres server process that dies under an open transaction crashes the backend (postgres.js null-socket write) #4041.
- BYO knowledge databases. An organization's own knowledge-database outage answers the platform's
DATABASE_UNAVAILABLEand goes unreported: bug(platform): an organization's own knowledge-database outage answers as the platform's DATABASE_UNAVAILABLE and goes unreported #4040. - Mid-boot outages. A database that goes away after the migrations succeeded but before pg-boss starts still fails the boot. The window is narrow.
Activity