3039bc14d6
## 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.
31 lines
1.2 KiB
TypeScript
31 lines
1.2 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { buildPrismaConnectionUrl } from "./prismaConnectionUrl";
|
|
|
|
describe("buildPrismaConnectionUrl", () => {
|
|
it("sets connect_timeout (the Postgres connector parameter), not the ignored connection_timeout", () => {
|
|
const url = buildPrismaConnectionUrl("postgresql://u:p@host:5432/db?schema=public", {
|
|
connectionLimit: "10",
|
|
poolTimeout: "0",
|
|
connectTimeout: "20",
|
|
applicationName: "svc",
|
|
});
|
|
|
|
expect(url.searchParams.get("connect_timeout")).toBe("20");
|
|
expect(url.searchParams.has("connection_timeout")).toBe(false);
|
|
expect(url.searchParams.get("connection_limit")).toBe("10");
|
|
expect(url.searchParams.get("pool_timeout")).toBe("0");
|
|
expect(url.searchParams.get("application_name")).toBe("svc");
|
|
});
|
|
|
|
it("preserves existing base query params", () => {
|
|
const url = buildPrismaConnectionUrl(
|
|
"postgresql://u:p@host:5432/db?schema=public&sslmode=require",
|
|
{ connectionLimit: "5", poolTimeout: "10", connectTimeout: "20", applicationName: "svc" }
|
|
);
|
|
|
|
expect(url.searchParams.get("schema")).toBe("public");
|
|
expect(url.searchParams.get("sslmode")).toBe("require");
|
|
expect(url.searchParams.get("connect_timeout")).toBe("20");
|
|
});
|
|
});
|