Realm functions have a 90 second timeout, which may cause an execution timeout error if your Realm function runs for longer than this window.
You can confirm the issue by navigation to Realm Application Logs, selecting Function > Type and Error > Status in the filter bar, and clicking Apply. Search for the log entry containing
timeout and observe if the
Time Taken column returns a value of around 90 seconds.
Reducing function execution time resolves this issue. Here are some solutions:
1. Optimize the query to reduce the total number of scanned documents per query by:
Using an appropriate index.
3. Separate your current Realm function into several smaller functions. Then add these functions into an (outer) function and execute the smaller functions in parallel to reduce runtime. However, note that the outer function must still complete within 90 seconds. To debug, you can add timing messages to the log after each smaller function block and review their execution times to understand where timeout occurs (see Troubleshooting Realm Functions for more information).
There is no way to extend this runtime limit currently. However, we periodically re-evaluate this request. Follow this feature request post for more information.