You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(readyz): a pool-exhausted relay reports unavailable with a healthy database, and nothing alerts on it #1356
On 2026-12-03 a self-hosted relay built from this repo served /readyz as HTTP 503 for at least an hour, with {"database":{"ok":false},"redis":{"ok":true}}, while the database was healthy: a fresh client with the relay's own credentials, connecting from a container attached to the same network, ran SELECT 1 in milliseconds. Restarting the relay restored /readyz to ok immediately.
Cause: the readiness ping needs a pool slot it cannot get
pingDatabase() in src/utils/admin-health.ts runs getMasterDbClient().raw('SELECT 1'). The master pool's max defaults to 3 (src/database/client.ts, DB_MAX_POOL_SIZE unset).
pg_stat_activity showed exactly three sessions for the relay's role in state active: three older than five minutes, the oldest over four hours. All three pool slots were held by queries that never completed, so every readiness ping waited for a free connection.
Why the timeout does not save it
pingDatabase races the query against a 3 s timer (DEFAULT_ADMIN_DEPENDENCY_PING_TIMEOUT_MS), but the timeout neither cancels the query nor destroys its connection. acquireConnectionTimeout is 60 s, so the ping gives up 57 s before the pool does, and the pending acquire stays in the queue. The result is not a slow answer but a permanent ok:false against a database that answers instantly.
Why nothing alerted
The deployment's container healthcheck and its uptime check both probe /, which answers 200 with an HTML page, so Docker reported healthy and the monitor stayed green for the whole outage. Only an external check that reads /readyz caught it, which is the point of a dependency probe.
Proposal
Run the readiness probe on a connection the probe owns (a dedicated small client, or statement_timeout on the pooled one), so a saturated application pool cannot make readiness lie and a hung probe is cancelled rather than leaked.
When the probe times out, destroy the connection it used instead of leaving it checked out; today a single stalled socket permanently removes one of three slots.
Deployment side: point the container healthcheck and the uptime monitor at /readyz. A 200 on / says nothing about Postgres or Redis.
The three stuck sessions were cleared by the restart before their query text could be captured; the pool monitor's N used / N free / N pending line every 60 s is the signal to read next time this happens.
Second occurrence, same signature — so the pool wedges again within a single uptime, not once.
beszel-baseline-check (redis+postgres-via-nostream) notified at ~13:23Z that /readyz fails; three probes answered 503 in 3.00s each with {"status":"unavailable","database":{"ok":false},"redis":{"ok":true}}.
docker ps said Up 12 hours (healthy): the container healthcheck still probes /, because the compose change to /readyz needs a recreate and has not had one.
docker restart nostream at 13:33Z cleared it; the next probe answered 200 with {"status":"ok","database":{"ok":true},"redis":{"ok":true}}.
The 3.00 s answers are pingDatabase()'s own timeout, not a slow database — a fresh client gets a slot in milliseconds, the relay's pool (max 3) does not. That is the acquire-timeout-versus-ping-timeout mismatch this issue describes, and the ordering is unchanged since the 01:15Z occurrence.
Code side is in review as #1362: pingDatabase() no longer takes a slot from the master pool — it opens its own client from the master connection config, bounded by ADMIN_DEPENDENCY_PING_TIMEOUT_MS for connect, query and statement, with an error listener and a close that cannot outlive the same deadline.
Measured against the relay's Postgres with all three pool slots held by pg_sleep(45):
The pooled raw('select 1') gave up at 3.0 s exactly as in both outages; the new probe answered ok in 11 ms.
Two deployment steps are left, and neither is in the repository's code:
The compose healthcheck already probes /readyz (containers/nostream/compose.yml:66), but a recreate is needed before it takes effect — the running container still probes /, which is why docker ps said healthy through both outages.
The Gatus row still probes http://nostream:8008 (containers/gatus/config/config.yaml:547) and should become /readyz. That file currently carries ~112 uncommitted lines from another session (UniFi/AP rows), so the edit should wait until that lands rather than be committed alongside it.
Until both land, the only check that reads /readyz is the consumer probe in containers/scripts/beszel-baseline-check, which caught both outages within its interval.
Container rebuilt from containers/compose.yml (networks cloudflare + gatus), running main — NIP-11 reports version: 3.17.1, which is main's, not rewrite/main's 3.11.0.
The Docker healthcheck now runs /readyz and reports healthy, so a wedged database pool surfaces at the container level instead of only through the external probe.
Public https://relay.cameri.dev/readyz answers 200 with both dependencies ok.
One detour worth recording: the first recreate ran from projects/nostream/docker-compose.yml (the repo's own upstream dev stack) and took the nostream name, which is loopback-only with no healthcheck — the relay answered 502 until it was torn down and the right stack came back up. docker inspect <c> --format '{{index .Config.Labels "com.docker.compose.project.config_files"}}' names the file that created a container, which is how that was diagnosed.
Still open: the Gatus row probes /, not /readyz (containers/gatus/config/config.yaml), so the external check keeps reporting healthy on a wedged pool until that edit lands.
Activity
chappie-daemon commentedon Dec 3, 2026
Second occurrence, same signature — so the pool wedges again within a single uptime, not once.
beszel-baseline-check(redis+postgres-via-nostream) notified at ~13:23Z that/readyzfails; three probes answered503in3.00seach with{"status":"unavailable","database":{"ok":false},"redis":{"ok":true}}.docker pssaidUp 12 hours (healthy): the container healthcheck still probes/, because the compose change to/readyzneeds a recreate and has not had one.docker restart nostreamat 13:33Z cleared it; the next probe answered200with{"status":"ok","database":{"ok":true},"redis":{"ok":true}}.The 3.00 s answers are
pingDatabase()'s own timeout, not a slow database — a fresh client gets a slot in milliseconds, the relay's pool (max 3) does not. That is the acquire-timeout-versus-ping-timeout mismatch this issue describes, and the ordering is unchanged since the 01:15Z occurrence.cameri commentedon Dec 3, 2026
@chappie-daemon assigned to you
chappie-daemon commentedon Dec 3, 2026
Code side is in review as #1362:
pingDatabase()no longer takes a slot from the master pool — it opens its own client from the master connection config, bounded byADMIN_DEPENDENCY_PING_TIMEOUT_MSfor connect, query and statement, with anerrorlistener and a close that cannot outlive the same deadline.Measured against the relay's Postgres with all three pool slots held by
pg_sleep(45):The pooled
raw('select 1')gave up at 3.0 s exactly as in both outages; the new probe answeredokin 11 ms.Two deployment steps are left, and neither is in the repository's code:
/readyz(containers/nostream/compose.yml:66), but a recreate is needed before it takes effect — the running container still probes/, which is whydocker pssaid healthy through both outages.http://nostream:8008(containers/gatus/config/config.yaml:547) and should become/readyz. That file currently carries ~112 uncommitted lines from another session (UniFi/AP rows), so the edit should wait until that lands rather than be committed alongside it.Until both land, the only check that reads
/readyzis the consumer probe incontainers/scripts/beszel-baseline-check, which caught both outages within its interval.chappie-daemon commentedon Dec 3, 2026
Deployed 2026-12-03T16:25Z.
containers/compose.yml(networkscloudflare+gatus), runningmain— NIP-11 reportsversion: 3.17.1, which is main's, notrewrite/main's 3.11.0./readyzand reports healthy, so a wedged database pool surfaces at the container level instead of only through the external probe.https://relay.cameri.dev/readyzanswers 200 with both dependencies ok.One detour worth recording: the first recreate ran from
projects/nostream/docker-compose.yml(the repo's own upstream dev stack) and took thenostreamname, which is loopback-only with no healthcheck — the relay answered 502 until it was torn down and the right stack came back up.docker inspect <c> --format '{{index .Config.Labels "com.docker.compose.project.config_files"}}'names the file that created a container, which is how that was diagnosed.Still open: the Gatus row probes
/, not/readyz(containers/gatus/config/config.yaml), so the external check keeps reporting healthy on a wedged pool until that edit lands.fix(readyz): probe Postgres on a connection the readiness check owns
fix(readyz): probe Postgres on a connection the readiness check owns (c…