import net from "node:net"; /** * How long a database client keeps retrying a refused first connection. * * A brand-new pod is often refused for a moment after it starts: on clusters * that enforce NetworkPolicy the pod's rules are still being programmed (about * 0.5 to 1 s), and DNS or the database itself may still be coming up. Without a * retry, the first query of a one-shot job (migrations, catalog import) fails * the rollout and long-running processes restart once. The window only applies * until the client has reached the server once; after that a refused * connection fails exactly as before so real outages surface immediately. */ export declare const DATABASE_BOOT_CONNECT_GRACE_MS = 15000; /** The subset of postgres.js connection options a custom socket factory receives. */ export type DatabaseSocketTarget = { host: readonly string[]; port: readonly number[]; path?: string | false | undefined; connect_timeout?: number | undefined; }; export type DatabaseConnectEndpoint = { kind: "tcp"; host: string; port: number; } | { kind: "path"; path: string; }; export type BootGraceSocketDependencies = { graceMs?: number; now?: () => number; sleep?: (ms: number) => Promise; connect?: (endpoint: DatabaseConnectEndpoint, timeoutMs: number | null) => Promise; open?: (endpoint: DatabaseConnectEndpoint) => net.Socket; }; export declare function isDatabaseBootTransientConnectError(error: unknown): boolean; /** Jittered delay before the next boot connect attempt: 100 ms doubling to 1 s. */ export declare function databaseBootConnectRetryDelayMs(attempt: number, random?: () => number): number; /** * Starts connecting and returns the socket at once, like postgres.js's own * connection path: a failure arrives as the socket's `error` and `close` * events, which postgres.js handles by failing the waiting query and putting * the connection back in its pool to reconnect later. */ export declare function openDatabaseSocket(endpoint: DatabaseConnectEndpoint): net.Socket; /** Opens one connected socket, failing on the first socket error or timeout. */ export declare function connectDatabaseSocket(endpoint: DatabaseConnectEndpoint, timeoutMs: number | null): Promise; /** * A postgres.js `socket` factory that retries a refused or reset connection * while the client is still booting (see {@link DATABASE_BOOT_CONNECT_GRACE_MS}). * One factory belongs to one client: every pooled connection shares the "has * reached the server" state, so the grace ends at the first success or when the * window since client creation has elapsed, whichever comes first. Each attempt * keeps the client's own `connect_timeout`. * * The factory never rejects. postgres.js does not recover a pooled connection * whose socket factory rejects: it fails the waiting query but never returns * the connection to its pool, so after a database restart every connection * leaked one by one and the client hung for good, even once the database was * back. Outside the grace, and when the grace gives up, the factory instead * returns a socket that is still connecting, so a failure reaches postgres.js * as socket events and the connection reconnects like any other. */ export declare function createBootGraceDatabaseSocket(dependencies?: BootGraceSocketDependencies): (target: DatabaseSocketTarget) => Promise; /** * postgres.js options that add the boot connect grace to a client for * `databaseUrl`. A multi-host URL keeps postgres.js's own host failover, which * a custom socket would replace, so it gets no factory. A `graceMs` of 0 * disables the grace: the first refused connection fails immediately. */ export declare function databaseBootConnectOptions(databaseUrl: string, graceMs?: number): { socket?: (target: DatabaseSocketTarget) => Promise; };