Function Limit Troubleshooting

Learn how Edge Functions manage CPU resources and what happens when limits are reached.

How isolates work

An isolate is like a worker that can handle multiple requests for a function. It works until it reaches either the wall clock time limit or CPU time limit. Edge Functions use isolates with soft and hard CPU limits.

Soft limit

When the isolate hits the soft limit, it retires. An isolate retiring means:

  • It won’t take on any new requests
  • It will finish processing requests it’s already working on
  • It keeps going until it hits the hard limit for CPU time or reaches the wall clock time limit, whichever comes first

Hard limit

If there are new requests after the soft limit is reached:

  • A new isolate is created to handle them
  • The original isolate continues processing any existing requests until it hits the hard limit or the time limit This ensures existing requests are completed while new ones are managed by a fresh isolate

Current limits

  • Wall clock time limit: 150 seconds on the Free plan, 400 seconds on paid plans
  • CPU execution time: 2 seconds of active computing accumulated per isolate

What happens when limits are exceeded

When your function exceeds one of the limits, you may see:

  • 546 error responses
  • Function termination with CPUTime or WallClockTime shutdown reason
  • Degraded performance as new isolates spin up

Wall clock time limit

When the wall clock time limit is reached, a 546 HTTP error is returned with the message “wall clock time limit reached”. If your function terminates with this warning, then this indicates that your function is exceeding the allowed execution time, signaling a long-running task.

Steps to Troubleshoot If you’re facing the “wall clock time limit reached” error with a 546 error code, here are actions to take:

  • Review Your Function’s Logic: Examine the operations within your edge function for any inefficiencies or prolonged processes. Consider optimizing code, minimizing unnecessary calculations, and implementing asynchronous operations where possible.

  • Divide Complex Tasks: For functions handling complex or extensive tasks, try breaking them down into smaller, discrete functions. This approach can help manage workloads more effectively and stay within time limits.

  • Monitor Execution Time: Use our logging or monitoring tools available to keep an eye on your function’s performance. This can pinpoint where optimizations are necessary. To access logs visit: Supabase Project Functions Select your function and click on Logs.

  • Check Our Guides: For more tips, refer to our debugging guide here: Debugging Edge Functions

Future Considerations There are plans to make the wall clock time limit configurable per project in the future. However, currently, the only way to adjust this limit is by self-hosting Edge Functions.

Stay updated on changes by regularly checking our changelog here.

CPU time limit

When your function exceeds CPU limits, a 546 HTTP error is returned with the message “CPU Time exceeded”.

If your function terminates with this warning, it can help to ensure that CPU usage is optimized within your functions.

Optimizing CPU usage

Profile your code

Identify CPU-intensive sections in your function:

  • Complex calculations
  • Data processing loops
  • Encryption operations

Optimize algorithms

  • Use more efficient data structures
  • Cache computed results
  • Reduce algorithmic complexity

Offload heavy work

  • Move intensive processing to background jobs
  • Use external services for heavy computations
  • Break large tasks into smaller functions

Log notification when function is shutdown

For additional visibility into function shutdowns, you can listen to the beforeunload event handler to be notified when the function is about to be shut down:

EdgeRuntime.waitUntil(asyncLongRunningTask())
// Use beforeunload event handler to be notified when function is about to shutdown
addEventListener('beforeunload', (ev) => {
console.log('Function will be shutdown due to', ev.detail?.reason)
// Save state or log the current progress
})
Deno.serve(async (req) => {
return new Response(...)
})

Additional resources

Go to the GitHub discussion