Skip to content

Commit 02a502f

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 189c94a commit 02a502f

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
@@ -893,11 +893,38 @@ async function handleProxyRequest(
893893
// Check request body size before sending
894894
validateRequestBodySize(body, requestId, `proxy:${toolId}`)
895895

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

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

0 commit comments

Comments
 (0)