🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
fix(auth): add custom timeout to sso config query (#2192)
Marc Klingene06b96a5ee80
diff --git a/ee/src/sso/index.ts b/ee/src/sso/index.tsindex 84e39f8114..d9ec40f603 100644--- a/ee/src/sso/index.ts+++ b/ee/src/sso/index.ts@@ -6,7 +6,7 @@ import CognitoProvider from "next-auth/providers/cognito";import Auth0Provider from "next-auth/providers/auth0";import AzureADProvider from "next-auth/providers/azure-ad";import { isEeAvailable } from "..";-import { prisma } from "@langfuse/shared/src/db";+import { type SsoConfig, prisma } from "@langfuse/shared/src/db";import { encrypt, decrypt } from "@langfuse/shared/encryption";import { SsoProviderSchema } from "./types";import { type NextApiRequest, type NextApiResponse } from "next";@@ -26,14 +26,36 @@ let cachedSsoConfigs: {async function getSsoConfigs(): Promise<SsoProviderSchema[]> {if (!isEeAvailable) return [];const CACHE_TTL = 60 * 1000; // 1 minute+ const DB_MAX_WAIT = 2000; // 2 seconds+ const DB_TIMEOUT = 3000; // 3 seconds// Set/refresh the cache if it's empty or expiredif (cachedSsoConfigs === null ||Date.now() - cachedSsoConfigs.timestamp > CACHE_TTL) {+ // findMany with custom timeout via $transaction+ let dbConfigs: SsoConfig[] = [];+ try {+ dbConfigs = await prisma.$transaction(+ async (prisma) => prisma.ssoConfig.findMany(),+ {+ maxWait: DB_MAX_WAIT,+ timeout: DB_TIMEOUT,+ }+ );+ } catch (e) {+ // cache empty array to prevent repeated DB calls on error+ cachedSsoConfigs = {+ data: [],+ timestamp: Date.now(),+ };++ // caught and logged in the caller+ throw e;+ }+// transform into zod object- const dbConfigs = await prisma.ssoConfig.findMany();const parsedSsoConfigs = dbConfigs.map((v) => {try {