@zedtech/zedkit-server
Retry transient Postgres failures
Map serialization/deadlock/connection errors to retry without duplicating SQLSTATE lists.
At a glance
- Who: Workers and job runners using
@zedtech/zedkit-corebackoff helpers. - What: Map serialization/deadlock/connection errors to retry without duplicating SQLSTATE lists.
- Use when: After a failed query in a retry loop.
- Avoid when: For HTTP mapping — use
pgErrorCodeand your API error model. - See also: Tell a Postgres conflict from a bug
Install
pnpm add @zedtech/zedkit-serverLatest: 1.3.1 (via changesets).
Example
import { pgErrorRetryable } from "@zedtech/zedkit-server";
import { computeBackoffMs } from "@zedtech/zedkit-server";
if (pgErrorRetryable(error) === true) {
await sleep(computeBackoffMs(attempt));
continue;
}Wraps: (none)
Tell a Postgres conflict from a bug
Extract the Postgres error code (also from an ORM-wrapped `cause`) so unique violations map to 409, not 500.
Derive purpose-bound keys from one master secret
Derive unrelated 32-byte keys per purpose from a single master with HKDF-SHA256, so rotation is a version bump.