Skip to content

Commit 048ff62

Browse files
majiayu000claude
andcommitted
fix(http): add timeout support to proxy requests
The previous implementation only added timeout to handleInternalRequest, but external API requests go through handleProxyRequest which was missing the timeout logic. This caused the proxy fetch to use default timeout instead of the user-configured value. - Add timeout parsing logic to handleProxyRequest - Add AbortSignal.timeout to proxy fetch call - Add user-friendly timeout error message Fixes the issue reported by @ARNOLDAJEE where 600000ms timeout setting was not taking effect for external API requests. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent c23eb1c commit 048ff62

File tree

1 file changed

+32
-5
lines changed

1 file changed

+32
-5
lines changed

apps/sim/tools/index.ts

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -897,11 +897,38 @@ async function handleProxyRequest(
897897
// Check request body size before sending
898898
validateRequestBodySize(body, requestId, `proxy:${toolId}`)
899899

900-
const response = await fetch(proxyUrl, {
901-
method: 'POST',
902-
headers,
903-
body,
904-
})
900+
// Determine timeout for proxy request: use params.timeout if provided, otherwise default
901+
// This ensures the proxy fetch itself doesn't timeout before the actual API request
902+
const DEFAULT_TIMEOUT_MS = 120000
903+
const MAX_TIMEOUT_MS = 600000
904+
let timeoutMs = DEFAULT_TIMEOUT_MS
905+
if (typeof params.timeout === 'number' && params.timeout > 0) {
906+
timeoutMs = Math.min(params.timeout, MAX_TIMEOUT_MS)
907+
} else if (typeof params.timeout === 'string') {
908+
const parsed = Number.parseInt(params.timeout, 10)
909+
if (!Number.isNaN(parsed) && parsed > 0) {
910+
timeoutMs = Math.min(parsed, MAX_TIMEOUT_MS)
911+
}
912+
}
913+
914+
let response: Response
915+
try {
916+
response = await fetch(proxyUrl, {
917+
method: 'POST',
918+
headers,
919+
body,
920+
signal: AbortSignal.timeout(timeoutMs),
921+
})
922+
} catch (fetchError) {
923+
// Handle timeout error specifically
924+
if (fetchError instanceof Error && fetchError.name === 'TimeoutError') {
925+
logger.error(`[${requestId}] Proxy request timed out for ${toolId} after ${timeoutMs}ms`)
926+
throw new Error(
927+
`Request timed out after ${timeoutMs}ms. Consider increasing the timeout value.`
928+
)
929+
}
930+
throw fetchError
931+
}
905932

906933
if (!response.ok) {
907934
// Check for 413 (Entity Too Large) - body size limit exceeded

0 commit comments

Comments
 (0)