fix: NVIDIA NIM API key validation timeout (bypass proxy fetch patch) (#3226)

NVIDIA NIM validation bypasses the proxy-patched fetch (504 fix) + combined with #3116 reliable probe model + test. Integrated into release/v3.8.11.
This commit is contained in:
MeAdityaB
2026-06-05 20:22:27 +05:30
committed by GitHub
parent dfcaeba6d9
commit 4dbbbaacf1
5 changed files with 119 additions and 9 deletions

View File

@@ -1,4 +1,4 @@
import { runWithProxyContext } from "@omniroute/open-sse/utils/proxyFetch.ts";
import { runWithProxyContext, getOriginalFetch } from "@omniroute/open-sse/utils/proxyFetch.ts";
import { FetchTimeoutError, fetchWithTimeout } from "@/shared/utils/fetchTimeout";
import {
OutboundUrlGuardError,
@@ -30,6 +30,10 @@ export interface SafeOutboundFetchOptions extends RequestInit {
retry?: SafeOutboundFetchRetryOptions | false;
guard?: SafeOutboundFetchGuard;
proxyConfig?: unknown;
/** Bypass the global proxy/TLS patched fetch and use the native Node.js
* fetch directly. Use when a provider endpoint has compatibility issues
* with the undici dispatcher layer. */
bypassProxyPatch?: boolean;
}
type SafeOutboundFetchPresetMap = {
@@ -51,7 +55,7 @@ export const SAFE_OUTBOUND_FETCH_PRESETS: SafeOutboundFetchPresetMap = {
},
},
validationWrite: {
timeoutMs: 7000,
timeoutMs: 15000,
allowRedirect: false,
retry: false,
},
@@ -264,6 +268,7 @@ export async function safeOutboundFetch(url: string | URL, options: SafeOutbound
retry,
guard = "none",
proxyConfig,
bypassProxyPatch = false,
signal,
...fetchOptions
} = options;
@@ -282,11 +287,15 @@ export async function safeOutboundFetch(url: string | URL, options: SafeOutbound
redirect,
signal,
timeoutMs,
// When bypassing the proxy patch, use the original native fetch directly.
fetchFn: bypassProxyPatch ? getOriginalFetch() : undefined,
});
const response = proxyConfig
? await runWithProxyContext(proxyConfig, executeFetch)
: await executeFetch();
const response = bypassProxyPatch
? await executeFetch()
: proxyConfig
? await runWithProxyContext(proxyConfig, executeFetch)
: await executeFetch();
if (!allowRedirect && response.status >= 300 && response.status < 400) {
const location = response.headers.get("location");

View File

@@ -13,10 +13,13 @@ const FETCH_TIMEOUT_MS = parseInt(process.env.FETCH_TIMEOUT_MS || "", 10) || DEF
interface FetchTimeoutOptions extends RequestInit {
timeoutMs?: number;
/** Alternative fetch function to use instead of globalThis.fetch.
* Pass getOriginalFetch() to bypass the proxy/TLS patch layer. */
fetchFn?: typeof globalThis.fetch;
}
export async function fetchWithTimeout(url: string | URL, options: FetchTimeoutOptions = {}) {
const { timeoutMs = FETCH_TIMEOUT_MS, signal: externalSignal, ...fetchOptions } = options;
const { timeoutMs = FETCH_TIMEOUT_MS, signal: externalSignal, fetchFn, ...fetchOptions } = options;
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
@@ -31,7 +34,8 @@ export async function fetchWithTimeout(url: string | URL, options: FetchTimeoutO
}
try {
const response = await fetch(url, {
const doFetch = fetchFn || globalThis.fetch;
const response = await doFetch(url, {
...fetchOptions,
signal: controller.signal,
});