Skip to content

feat(startup): wait for Postgres and IISA instead of exiting - #849

Merged
cjorge-thegraph merged 4 commits into
mainfrom
cjorge/wait-for-postgres-and-iisa-at-start
Nov 19, 2026
Merged

cjorge-thegraph merged 4 commits into
mainfrom
cjorge/wait-for-postgres-and-iisa-at-start

Conversation

@cjorge-thegraph

@cjorge-thegraph cjorge-thegraph commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Dipper exited when IISA had not passed its health check after 3 tries 2 seconds apart, and when its first database connect failed in any way the pool does not retry itself (the pool only retries a refused connection or a Postgres "starting up", and only for its 30s acquire timeout). Both dependencies are away for longer in ordinary operations: IISA's own rollout stops the old pod before the new one is ready, 90 seconds or more by its readiness probe, and a database restarting or failing over can drop connections or be unreachable for a while. A dipper starting in such a gap restarted in a loop until it closed.

  • startup::retry_within retries with pauses of 1s doubling to at most 30s, for up to a wait, and gives up at once on an error not worth retrying.
  • IISA: wait_for_iisa waits up to iisa.startup_wait (new, 180s by default) and then exits as before.
  • Database: db::connect waits up to db.connect_wait (new, 120s by default) for an unreachable or dropping server. A server that answers with a refusal (a wrong password, a missing database), a bad option or a TLS failure still ends the wait at once.
  • The startup probe now allows 900s, as the RPC domain fetch, the indexer URL snapshot and the 2 new waits can exceed 600s together.

The probes are otherwise unchanged. Liveness stays on /health, which is local to the process, and readiness stays the TCP check of the admin port, which opens once startup has finished. Neither depends on the database or IISA: every pod shares those, so a blip would mark the Deployment unavailable with nothing to route around. Their reachability belongs in metrics and alerts instead.

The RPC-domain and indexer-URL loops keep their own retries; they could move onto retry_within in a follow-up.

Tests:

  • waiting_for_iisa_rides_out_an_iisa_rollout (paused clock) failed against the old 3-try loop and passes now.
  • connect_retries_a_server_that_drops_the_connection saw 1 attempt on main and 2 now.
  • 4 paused-clock tests pin the backoff.
  • just fmt-check, just check, just test-unit pass locally.

Changes after review

  • Waits stay within their bounds. The database wait now tries 1 connection at a time, each cut off at what is left of db.connect_wait (10s at most), and opens the pool once one gets in. Asking the pool made each attempt wait its 30s acquire timeout and hid the cause behind "pool timed out". An IISA health check that hangs is cut off at what is left of iisa.startup_wait.
  • Only failures that may clear up are retried. An I/O error is retried unless it is invalid data, which is how rustls reports a rejected certificate. A database error is retried only for 57P03 (starting up), 53300 (too many connections) or class 08 (connection failure). A timed-out attempt is retried. Protocol errors, refused passwords, missing databases and bad options end the wait at once. Before, TLS failures and protocol errors were retried for the whole wait.
  • The final error gives the tries made and the time actually waited, not the configured wait.
  • The startup probe allows 900s, and its comment adds up the steps; the earlier claim that startup stayed within 600s was wrong.
  • The tests that could not fail are replaced. A hanging IISA check must end at the 60s wait. A server that accepts and never answers must be given up on within a 2s wait. Every attempt is given the time left. The retry decision is checked on the error shapes sqlx and rustls really return.

🤖 Generated with Claude Code

cjorge-thegraph and others added 4 commits November 18, 2026 12:42
Dipper exited when IISA had not answered its health check after 3 tries 2 seconds apart, and
when its first database connect failed other than by a refusal the pool retries itself. Both
are away for longer in ordinary operations: IISA's own rollout stops its old pod before the new
one is ready, 90 seconds or more, and a database restarting or failing over can drop
connections or be unreachable for a while. A dipper starting in such a gap restarted in a loop
until it closed.

Startup now waits for both, with pauses of 1 second doubling to at most 30, for up to
`iisa.startup_wait` (180 seconds by default) and `db.connect_wait` (120 by default), then
exits as before. A database that answers with a refusal, such as a wrong password, or a
connection set up wrongly still ends the wait at once. Together with the existing RPC and
indexer URL retries, startup stays within the deployment's 600-second startup probe.

The health server also answers `GET /ready`, 200 while a `SELECT 1` succeeds within 2 seconds
and 503 otherwise, and the manifest's readiness probe uses it instead of a TCP check of the
admin port, so a pod that lost its database stops counting as available while liveness, which
a restart would not fix, stays unaffected.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Readiness decides whether a pod counts as available and gets traffic. Tying it to the database,
which every dipper shares, would only turn a database blip into the Deployment going
unavailable and back, with nothing to route around: dipper runs as 1 pod, and its admin port
takes no load-balanced traffic. Readiness stays the TCP check of the admin port, which opens
once startup has finished, and the database's reachability belongs in metrics and alerts.

This takes `/ready` back out and keeps the startup waits for the database and IISA.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…may clear up

Review found the waits did not do what they said:

- The database wait asked the pool, which blocks each attempt for its 30s acquire timeout and
  then reports only that it timed out, so a 120s wait took about 127s and hid the cause. It now
  tries 1 connection at a time, each cut off at what is left of the wait (10s at most), and
  opens the pool once one gets in. An IISA health check that hangs is likewise cut off at what
  is left, where it could add its 30s request timeout before.
- Errors that fail the same way every time were retried for the whole wait: rustls reports a
  rejected certificate as an I/O error of invalid data, and protocol errors mean something other
  than Postgres answered. Now an I/O error is retried unless it is invalid data, a database
  error only when Postgres is starting up (57P03), out of connections (53300) or reports a
  connection failure (class 08), and a timed-out attempt always; nothing else is.
- The final error gave the configured wait as the time waited. It now gives the tries made and
  the time actually waited.
- The startup probe allowed 600s, which the RPC domain fetch, the indexer URL snapshot and the
  2 new waits can exceed together. It allows 900s, and its comment adds the steps up.

The tests that could not fail are replaced: a hanging IISA check must end at the 60s wait, a
server that accepts and never answers must be given up on within a 2s wait, every attempt is
given the time left, and the retry decision is checked on the error shapes sqlx and rustls
really return.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…res-and-iisa-at-start

Resolves db.rs against #847 and #850. The startup probe now fails before the pool does, so a
refused password check gets #850's explanation there as well, and the TLS tests, whose stub
drops each connection after its handshake, set a 1s connect wait instead of waiting 120s out.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@cjorge-thegraph
cjorge-thegraph marked this pull request as ready for review November 19, 2026 20:32
@cjorge-thegraph
cjorge-thegraph merged commit d1406d4 into main Nov 19, 2026
13 checks passed
MoonBoi9001 pushed a commit that referenced this pull request Nov 23, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.3.4](v0.3.3...v0.3.4)
(2026-11-23)


### Added

* **config:** type secrets as such and read config from several files
([#857](#857))
([fe92407](fe92407))
* **db:** connect to Postgres over TLS
([#847](#847))
([2673181](2673181))
* **db:** let only 1 dipper process write, enforced by the database
([#858](#858))
([6f88900](6f88900))
* **db:** make the database password optional
([#850](#850))
([cb5d3b1](cb5d3b1))
* **metrics:** serve Prometheus metrics and optionally log as JSON
([#851](#851))
([523819e](523819e))
* **rpc:** expose effective indexing targets and chain identity
([#860](#860))
([aafc0ce](aafc0ce))
* **startup:** wait for Postgres and IISA instead of exiting
([#849](#849))
([d1406d4](d1406d4))


### Fixed

* **db:** sslmode=verify-ca skips the hostname check, as libpq does
([#859](#859))
([5fec97d](5fec97d))
* **k8s:** roll dipper out one pod at a time
([#846](#846))
([de57e46](de57e46))
* **shutdown:** stop taking jobs first and fit the teardown in its
budget ([#854](#854))
([a1bc47d](a1bc47d))


### Tests

* run each test's Postgres on its Unix socket only
([#861](#861))
([bc9e2b2](bc9e2b2))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@MoonBoi9001
MoonBoi9001 deleted the cjorge/wait-for-postgres-and-iisa-at-start branch November 26, 2026 13:01
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.

1 participant