Files
Eric Allam 3039bc14d6 fix(webapp): honor the configured database connect timeout (#4513)
## Summary

Every Prisma client built its connection URL with a `connection_timeout`
query param, but the Postgres connector's parameter is
`connect_timeout`. The misspelled param is silently ignored, so all
clients fell back to Prisma's 5s default instead of the configured
timeout. When establishing a new connection briefly took longer than 5s
(for example during connection spikes), it failed with `Can't reach
database server` even though the database was healthy.

## Fix

All four client builders now construct their connection URL through one
shared helper (`buildPrismaConnectionUrl`) that sets `connect_timeout`,
so the configured value actually applies, and the parameter name lives
in exactly one place. Covered by a unit test.
2026-08-05 15:52:12 +01:00

19 lines
565 B
TypeScript

export type PrismaConnectionParams = {
connectionLimit: string;
poolTimeout: string;
connectTimeout: string;
applicationName: string;
};
export function buildPrismaConnectionUrl(
baseUrl: string | URL,
params: PrismaConnectionParams
): URL {
const url = new URL(baseUrl);
url.searchParams.set("connection_limit", params.connectionLimit);
url.searchParams.set("pool_timeout", params.poolTimeout);
url.searchParams.set("connect_timeout", params.connectTimeout);
url.searchParams.set("application_name", params.applicationName);
return url;
}