Unified · Split
| @@ -105,6 +105,11 @@ const handle = async (request: NextRequest, context: RouteContext): Promise<Resp · 104 unmodified lines | ||
| 105 | 105 | |
| 106 | 106 | return runtime.handleControlPlane(applyPrincipalHeaders(controlPlaneRequest, principal)); |
| 107 | 107 | } catch (cause) { |
| 108 | + console.error("[control-plane] request failed", { | |
| 109 | + method: request.method, | |
| 110 | + path: request.nextUrl.pathname, | |
| 111 | + cause, | |
| 112 | + }); | |
| 108 | 113 | return storageErrorResponse("control-plane.request", cause); |
| 109 | 114 | } |
| 110 | 115 | }; |
| @@ -67,6 +67,20 @@ type SqlRuntime = { · 66 unmodified lines | ||
| 67 | 67 | close: () => Promise<void>; |
| 68 | 68 | }; |
| 69 | 69 | |
| 70 | +const resolvePostgresMaxConnections = (): number => { | |
| 71 | + const configured = process.env.CONTROL_PLANE_POSTGRES_MAX_CONNECTIONS | |
| 72 | + ?? process.env.POSTGRES_MAX_CONNECTIONS; | |
| 73 | + | |
| 74 | + if (configured) { | |
| 75 | + const parsed = Number.parseInt(configured, 10); | |
| 76 | + if (Number.isFinite(parsed) && parsed > 0) { | |
| 77 | + return parsed; | |
| 78 | + } | |
| 79 | + } | |
| 80 | + | |
| 81 | + return process.env.NODE_ENV === "production" ? 1 : 10; | |
| 82 | +}; | |
| 83 | + | |
| 70 | 84 | const sanitizePostgresUrl = (value: string): string => { |
| 71 | 85 | try { |
| 72 | 86 | const parsed = new URL(value); |
| @@ -108,7 +122,7 @@ const createPostgresRuntime = async ( · 35 unmodified lines | ||
| 108 | 122 | ): Promise<SqlRuntime> => { |
| 109 | 123 | const client = postgres(sanitizePostgresUrl(databaseUrl), { |
| 110 | 124 | prepare: false, |
| 111 | − max: 10, | |
| 125 | + max: resolvePostgresMaxConnections(), | |
| 112 | 126 | ...(applicationName ? { connection: { application_name: applicationName } } : {}), |
| 113 | 127 | }); |
| 114 | 128 | |