From df85e16d7a27969aea0b27804ee896308afd5eef Mon Sep 17 00:00:00 2001 From: Agung Gunawnan Date: Fri, 28 Aug 2026 17:05:55 +0700 Subject: [PATCH] fix(providers): time out connection tests and guard undefined names Apply a 15s AbortSignal timeout in fetchWithConnectionProxy when the caller supplies none, so provider connection tests stop hanging and exhausting the browser socket pool. Also make matchSearch return false for falsy provider names instead of crashing the providers page. --- src/app/(dashboard)/dashboard/providers/page.js | 8 +++++--- src/app/api/providers/[id]/test/testUtils.js | 6 ++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/app/(dashboard)/dashboard/providers/page.js b/src/app/(dashboard)/dashboard/providers/page.js index b1c23de2..f9a46154 100644 --- a/src/app/(dashboard)/dashboard/providers/page.js +++ b/src/app/(dashboard)/dashboard/providers/page.js @@ -115,9 +115,11 @@ export default function ProvidersPage() { return () => unregisterSearch(); }, [registerSearch, unregisterSearch]); - const matchSearch = (name) => - !searchQuery.trim() || - name.toLowerCase().includes(searchQuery.trim().toLowerCase()); + const matchSearch = (name) => { + if (!searchQuery.trim()) return true; + if (!name) return false; + return name.toLowerCase().includes(searchQuery.trim().toLowerCase()); + }; const sortByPriority = (entries, authType) => [...entries].sort(([ka, a], [kb, b]) => { diff --git a/src/app/api/providers/[id]/test/testUtils.js b/src/app/api/providers/[id]/test/testUtils.js index b9bd966a..bd0c4782 100644 --- a/src/app/api/providers/[id]/test/testUtils.js +++ b/src/app/api/providers/[id]/test/testUtils.js @@ -445,6 +445,12 @@ async function testOAuthConnection(connection, effectiveProxy = null) { } async function fetchWithConnectionProxy(url, options = {}, effectiveProxy = null) { + // Add a 15-second timeout to prevent connection testing from hanging indefinitely + // and exhausting the browser/Node.js connection pools. + if (!options.signal) { + options.signal = AbortSignal.timeout(15000); + } + // Vercel relay: forward via relay URL if (effectiveProxy?.vercelRelayUrl) { const { proxyAwareFetch } = await import("open-sse/utils/proxyFetch.js");