Connecting
How a store module waits for its database, which failures stop it at once, and when to start without one.
By default connect waits for the database. The wait is one bound for the whole module, connect_within, 30 seconds unless set, and one retry loop inside it.
| Builder method | Default | Effect |
|---|---|---|
.connect_within(d) | 30 s | The total bound on connecting. Zero is refused at wire(). It also bounds the wait for the migration lock. |
.retries(n) | unbounded | Attempts after the first. The bound ends the loop unless a count ends it earlier, with the last attempt's error. |
.backoff(d) | 1 s | The constant wait between attempts. |
.lazy() | off | Start without waiting for the database. |
.without_health_check() | off | Leave the store's check out. |
When the bound passes, the start fails with a retryable error, which ulo::is_permanent answers false for.
Failures that stop at once
Some failures only the operator can mend. A store marks them ulo::Permanent, and the loop stops at its first attempt rather than retrying to the bound. ulo::is_permanent tells them from the retryable ones.
| Store | Permanent | Retried |
|---|---|---|
| SQLx | A configuration error. A database error with SQLSTATE class 28 or 3D000 on Postgres, 28000 or 42000 on MySQL, or CANTOPEN on SQLite. A TLS configuration SQLx cannot use. A server certificate rustls refuses. | Any other I/O error, a pool timeout, a crashed worker, and a certificate past or before its validity period, which reads the local clock. |
| SeaORM | As SQLx, through the SQLx error it carries. | As SQLx. |
| Diesel | Bad credentials and an unknown database, told apart by the message text. | A failed send, a bad connection, any message not recognised. |
| MongoDB | Authentication, invalid arguments, invalid TLS configuration, an incompatible server. | Server selection and DNS resolution failures. |
| Redis | A wrong password, an invalid client configuration. | I/O errors and timeouts. |
Bad credentials therefore stop the start at its first attempt, and an unreachable server is retried until the bound.
SQLx reports a refused connection only after its pool's acquire timeout, so one attempt against an unreachable server lasts acquire_timeout_secs, 5 seconds unless set. SQLx's own default, 30 seconds, equals the default total bound and would allow a single attempt.
Diesel's errors lose the SQLSTATE, so the store matches the message against fragments of the servers' English refusals. A server whose messages are in another language has bad credentials retried to the bound.
Lazy modules
.lazy() omits the wait. connect returns at once, readiness is false, and the store's check stays down until the first ping succeeds.
// `connect` does not wait for the database, and the migrations need it, so a lazy
// store runs none: the schema is the deployment's.
m.import(store.lazy());A lazy module is refused at wire() in two cases, each with a report that names the call sites:
.lazy()beside.migrate(..), because migrations run at the start and need the database. The error isLazyWithMigrationsand names both calls..lazy()on options whosecreateconnects, which is amongodb+srv://URI whose DNS lookup is part of creating the client.
Runtime
A store creates its client, pings, migrates and closes as tasks on the runtime the application was given, so whatever the library spawns at creation runs there. The check reads the runtime's name and does no ambient lookup. A runtime other than tokio fails connect permanently.
Settings and identity
The options are a module's identity: two equal configurations are one module and a different URL is another. The builder knobs are outside the identity and are the module's settings. Two imports with equal options and different settings are refused by wire() as DifferingSettings, naming both import sites and each knob that differs.