ulo
ulo
Documentation

Start here

Coming from NestJSNestJS topics, mapped

The model

Protocols

Integrations

DatabaseConnectingMigrationsSeveral instancesSQLxSeaORMDieselMongoDBRedis

Operating

Reference

Database

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 methodDefaultEffect
.connect_within(d)30 sThe total bound on connecting. Zero is refused at wire(). It also bounds the wait for the migration lock.
.retries(n)unboundedAttempts after the first. The bound ends the loop unless a count ends it earlier, with the last attempt's error.
.backoff(d)1 sThe constant wait between attempts.
.lazy()offStart without waiting for the database.
.without_health_check()offLeave 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.

StorePermanentRetried
SQLxA 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.
SeaORMAs SQLx, through the SQLx error it carries.As SQLx.
DieselBad credentials and an unknown database, told apart by the message text.A failed send, a bad connection, any message not recognised.
MongoDBAuthentication, invalid arguments, invalid TLS configuration, an incompatible server.Server selection and DNS resolution failures.
RedisA 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.

examples/35-db-sqlx/src/lib.rs
// `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 is LazyWithMigrations and names both calls.
  • .lazy() on options whose create connects, which is a mongodb+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.

Database

A database is a module that reads its options from configuration, connects under a bound, contributes a health check and closes with the application.

Migrations

Run migrations at startup, once across replicas, under a lock the store takes on a dedicated connection.

On this page

Failures that stop at onceLazy modulesRuntimeSettings and identity