Repository navigation
fix(platform): log pg-boss's failed polls once per database outage - #3548
Merged
Merged
Conversation
pg-boss emits every failed poll of every queue's worker as an error event, and createBoss dumped each one in full: 677 events, some 11,800 log lines, in one 20 s database restart. An unavailable database (isDatabaseUnavailable) is now one warn line per outage, re-armed once a pg-boss worker's poll succeeds; any other pg-boss error is still logged in full. A worker's failure arrives as a plain copy of the error with its queue appended to the message, so the classifier reads through that suffix and describeDatabaseError reads a plain copy.
This was referenced Oct 1, 2026
Closed
4 of 5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
During a database outage pg-boss logged every failed worker poll as a full error dump. Now an unavailable database logs one warn line per outage in the job queue, and the line is re-armed once a poll succeeds. Every other pg-boss error is still logged in full. This is the follow-up #3506 left open (task TALE-51). There is no GitHub issue.
Problem
errorevent. That covers each queue's worker poll (every 2 s, about 60 queues), the queue cache, the cron clock and its pool's idle clients.createBosspassed each event toconsole.error.isDatabaseUnavailable:(Queue: <name>, Worker: <id>)to the error's message.queueandworkeradded.code, so coded errors still classify. But node-postgres's code-lessConnection terminated unexpectedlyis recognised only by its exact message, so the suffix hides it.describeDatabaseErrorprinted any non-Errorvalue as[object Object].Change
backend/jobs/boss.ts:createBosssends pg-boss'serrorevent throughlogErrors:isDatabaseUnavailable(…, { fromDatabase: true }). pg-boss's errors all come from its own node-postgres pool, so a bare socket error is the database's.[backend] pg-boss: database unavailable, polls fail quietly until one succeeds: <code> <message>. Later failures stay quiet until a worker'slastFetchedOnis newer than that line (getWipData({ includeInternal: true })), which re-arms it.console.error('[backend] pg-boss error:', error).backend/db/unavailable.ts:describeDatabaseErrorreadscodeandmessageoff any object, including a plain copy. The module comment names the new consumer.PERF-B6(job-queue log through two database restarts), with the suite's box count raised to 18;pins.mdrow explaining why the box exists;automation.mdrow pointing at the unit test.Proof
Unit test,
backend/jobs/boss.test.ts(new). It runs on the realPgBossemitter returned bycreateBoss. Its errors come from real node-postgres connection failures: a refused connection, a server that hangs up mid-handshake (Connection terminated unexpectedly), and a fake server that answers FATAL57P03 the database system is starting up. The test also uses a realpg.DatabaseError57P01. Each error is shaped the way a pg-boss 12 worker re-emits it.console.error. A42P01that follows is still logged in full.timeout exceeded when trying to connect) and28P01are still logged in full.Without the change, three of the four tests fail (the burst logs no warning, the hang-up hits
console.error, and the re-arm test sees no warning). The "logged in full" case passes on both, as a guard.db/unavailable.test.tsgains a case for describing a plain copy.End to end, the #3506 restart scenario.
ROLE=all(node … backend/main.ts) against a realtale-dbcontainer. Each restart wasdocker stop(SIGINT, a fast shutdown), 20 s down, thendocker start, and this happened twice. Lines were counted from the stop until 15 s after the database was back.pg-boss error:events, 11,850 log linespg-boss: database unavailable, … 57P01 terminating connection due to administrator commandThe process stayed up in both runs.
Checklist
bun run checkpasses (format, lint, typecheck, all tests). Partly; CI runs the rest. These passed locally:oxlinton the four changed TS files;tscon a config rooted at the changed files plusbackend/main.ts;unavailable.ts's importers: 32 files, 266 tests (jobs/,db/unavailable,realtime/sse,auth/,error-reporting,rest/v1);bun run lint:sastpasses (Opengrep) on the changed files: 0 findings.docs/{en,de,fr}/: one sentence on the observability page.README.md/README.de.md/README.fr.md: N/A, nothing they describe changed.bun run lint:manualpasses, and so doescheck-guideonperformance.md.Test plan
bunx vitest --run --project server backend/jobs/boss.test.ts backend/db/unavailable.test.tsinservices/platform.PERF-B6:docker compose logs -f backend-worker backend-api.docker compose restart db, wait for healthy, then restart it again.pg-boss: database unavailable …warning per container per restart, and nopg-boss error:dump.Open
LISTEN/NOTIFY connection endedin full if a connection drops without a FATAL message. That is one line per drop and says nothing about the database's state. A fast shutdown sends 57P01 first, which is covered.