Skip to content

Conversation

@mandarini
Copy link
Contributor

@mandarini mandarini commented Nov 6, 2025

🔍 Description

This PR addresses issue #1399 by adding a configurable client-side timeout for Functions invocations and by normalizing abort/timeouts into a typed FunctionsFetchError. Callers can now increase the client timeout when calling supabaseClient.functions.invoke(...) and reliably detect timeout/abort failures across environments.

What changed?

  • Added an optional timeout parameter to the Functions client invocation (invoke) so callers can control how long the client will wait before aborting the request.
    • Usage: supabaseClient.functions.invoke('fn-name', { /* ... */, timeout: <number in ms> })
  • When a request is aborted or hits the configured timeout, the Functions client now throws a FunctionsFetchError with a standardized kind (e.g. "timeout" or "abort").
    • The original error is preserved as the cause where supported, and message/name/stack are retained.
  • Existing non-abort/fetch errors are left unchanged.
  • Unit tests added for:
    • invoking with a short timeout -> throws FunctionsFetchError of kind "timeout"
    • aborted request via AbortController -> throws FunctionsFetchError of kind "abort"
    • non-abort network errors remain unchanged

Why was this change needed?

Issue #1399 reported that long-running edge functions were being cut off by a hard 60s client timeout and users had no way to increase it. Adding a user-configurable timeout fixes that UX gap. At the same time, different environments surface abort/timeouts with different error shapes (DOMException, AbortError, etc.), which makes it hard to handle these failures consistently. Normalizing those into FunctionsFetchError with an explicit kind gives consumers a single, stable error to catch and inspect.

Closes #1399

📝 Additional notes

  • Backwards-compatible: API surface is extended with an optional timeout option; no breaking changes to existing signatures.
  • Recommend documenting the new timeout option in the Functions client docs and showing an example for both browser and React Native usage.
  • Tests are included to validate behavior across abort and timeout scenarios.

@mandarini mandarini self-assigned this Nov 6, 2025
@github-actions github-actions bot added the functions-js Related to the functions-js library. label Nov 6, 2025
@mandarini mandarini linked an issue Nov 6, 2025 that may be closed by this pull request
2 tasks
@mandarini mandarini changed the title fix(functions): ensure timeout and abort errors return FunctionsFetchError fix(functions): normalize abort/timeout errors as FunctionsFetchError Nov 6, 2025
@mandarini mandarini changed the title fix(functions): normalize abort/timeout errors as FunctionsFetchError fix(functions): add configurable timeout and normalize abort/timeout errors as FunctionsFetchError Nov 6, 2025
@mandarini mandarini marked this pull request as ready for review November 6, 2025 13:55
@mandarini mandarini requested review from a team as code owners November 6, 2025 13:55
@mandarini mandarini merged commit 6ee3546 into master Nov 6, 2025
37 of 39 checks passed
@mandarini mandarini deleted the fix/timeout-edge branch November 6, 2025 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

functions-js Related to the functions-js library.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unable to increase client timeout for calling edge functions

3 participants