Skip to content

Commit 426ccb2

Browse files
waleedlatif1claude
andcommitted
fix(timeout): honor timeout config for internal routes and fix type coercion
- Add AbortController support for internal routes (/api/*) to honor timeout - Fix type coercion: convert string timeout from short-input to number - Handle NaN gracefully by falling back to undefined (default timeout) Fixes #2786 Fixes #2242 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 3798352 commit 426ccb2

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

apps/sim/tools/index.ts

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -625,11 +625,29 @@ async function executeToolRequest(
625625
let response: Response
626626

627627
if (isInternalRoute) {
628-
response = await fetch(fullUrl, {
629-
method: requestParams.method,
630-
headers: headers,
631-
body: requestParams.body,
632-
})
628+
// Set up AbortController for timeout support on internal routes
629+
const controller = new AbortController()
630+
const timeoutId = requestParams.timeout
631+
? setTimeout(() => controller.abort(), requestParams.timeout)
632+
: undefined
633+
634+
try {
635+
response = await fetch(fullUrl, {
636+
method: requestParams.method,
637+
headers: headers,
638+
body: requestParams.body,
639+
signal: controller.signal,
640+
})
641+
} catch (error) {
642+
if (timeoutId) clearTimeout(timeoutId)
643+
// Convert AbortError to a timeout error message
644+
if (error instanceof Error && error.name === 'AbortError') {
645+
throw new Error(`Request timed out after ${requestParams.timeout}ms`)
646+
}
647+
throw error
648+
} finally {
649+
if (timeoutId) clearTimeout(timeoutId)
650+
}
633651
} else {
634652
const urlValidation = await validateUrlWithDNS(fullUrl, 'toolUrl')
635653
if (!urlValidation.isValid) {

apps/sim/tools/utils.ts

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

126-
// Get timeout from params (if specified)
127-
const timeout = params.timeout as number | undefined
126+
// Get timeout from params (if specified) and ensure it's a number
127+
// The short-input subBlock returns a string, so we need to convert it
128+
const rawTimeout = params.timeout
129+
const timeout = rawTimeout != null ? Number(rawTimeout) : undefined
128130

129-
return { url, method, headers, body, timeout }
131+
return { url, method, headers, body, timeout: Number.isNaN(timeout) ? undefined : timeout }
130132
}
131133

132134
/**

0 commit comments

Comments
 (0)