Skip to content

Commit 8104f29

Browse files
committed
fix: add default timeout for internal routes and validate finite timeout
- Internal routes now use same 5-minute default as external routes - Added Number.isFinite() check to reject Infinity values
1 parent d442ab7 commit 8104f29

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

apps/sim/tools/index.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -627,9 +627,8 @@ async function executeToolRequest(
627627
if (isInternalRoute) {
628628
// Set up AbortController for timeout support on internal routes
629629
const controller = new AbortController()
630-
const timeoutId = requestParams.timeout
631-
? setTimeout(() => controller.abort(), requestParams.timeout)
632-
: undefined
630+
const timeout = requestParams.timeout || 300000
631+
const timeoutId = setTimeout(() => controller.abort(), timeout)
633632

634633
try {
635634
response = await fetch(fullUrl, {
@@ -641,11 +640,11 @@ async function executeToolRequest(
641640
} catch (error) {
642641
// Convert AbortError to a timeout error message
643642
if (error instanceof Error && error.name === 'AbortError') {
644-
throw new Error(`Request timed out after ${requestParams.timeout}ms`)
643+
throw new Error(`Request timed out after ${timeout}ms`)
645644
}
646645
throw error
647646
} finally {
648-
if (timeoutId) clearTimeout(timeoutId)
647+
clearTimeout(timeoutId)
649648
}
650649
} else {
651650
const urlValidation = await validateUrlWithDNS(fullUrl, 'toolUrl')

apps/sim/tools/utils.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,11 @@ export function formatRequestParams(tool: ToolConfig, params: Record<string, any
123123
}
124124
}
125125

126-
// Get timeout from params (if specified) and ensure it's a valid positive number
127-
// The short-input subBlock returns a string, so we need to convert it
126+
// Get timeout from params (if specified)
128127
const rawTimeout = params.timeout
129128
const timeout = rawTimeout != null ? Number(rawTimeout) : undefined
130129
const validTimeout =
131-
timeout != null && !Number.isNaN(timeout) && timeout > 0 ? timeout : undefined
130+
timeout != null && Number.isFinite(timeout) && timeout > 0 ? timeout : undefined
132131

133132
return { url, method, headers, body, timeout: validTimeout }
134133
}

0 commit comments

Comments
 (0)